How to know the Elastic IP of ec2 Linux instance

0

I've allocated an elastic IP to my EC2 Linux instance. Then, EC2 Instance Public IPv4 and Elastic IP appear to be the same, Please check following screenshot from the AWS EC2 Console: Enter image description here

Using the ec2-metadata ( EC2 Instance Metadata Service (IMDS) ) I can retrieve the following details: Instance ID, Instance Type, Public IPv4, Public IPv4 DNS, Tags etc   But I can't seem to access information about the Elastic IP from my Linux instance with the help of ec2-metadata

Thank you in advance for your assistance, and I look forward to your valuable input.

Best regards, Samadhan

  • Have you been able to resolve your issue? If so, would you select an answer that matched your issue to close out the thread?

profile picture
質問済み 8ヶ月前458ビュー
3回答
1
承認された回答

I think the most reliable way to see what public IP address your instance is using is to ask a third party service what address you're calling from. The public IP address of you interfaces is not visible to the operating system.

On Linux, you can run the following commands:

  • curl http://checkip.amazonaws.com
  • dig +short myip.opendns.com @resolver1.opendns.com
  • dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
  • host myip.opendns.com resolver1.opendns.com
  • dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'
AWS
LondonX
回答済み 8ヶ月前
profile picture
エキスパート
レビュー済み 5ヶ月前
0

Hi,

From this document you can know that when you bind an elastic IP to an instance, public-ipv4 is the address of the elastic IP:

CategoryDescriptionVersion when category was released
public-ipv4The public IPv4 address. If an Elastic IP address is associated with the instance, the value returned is the Elastic IP address.2007-01-19

Hope this can help you! :)

回答済み 8ヶ月前
  • Actually, I tried to assign private IP with which to associate the elastic IP address, but it only assigned the public IP as the elastic IP. Can we know if elastic IP is public or not?

0

You don't say what operating system that you're running so it's difficult to provide specific advice. That said:

To retrieve the public IP address associated with your instance, first you need to know the MAC address assigned to it. Then you can query IMDS. The following example assumes Amazon Linux and IMDSv1:

myMacAddress=$(ip link show eth0 | grep ether | awk '{print $2}')
curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/${myMacAddress}/ipv4-associations/
profile pictureAWS
エキスパート
回答済み 8ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ