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
asked 7 months ago441 views
3 Answers
1
Accepted Answer

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
answered 7 months ago
profile picture
EXPERT
reviewed 4 months ago
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! :)

answered 7 months ago
  • 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
EXPERT
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions