How to know the Elastic IP of ec2 Linux instance


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 3 months ago214 views
3 Answers
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
  • dig +short
  • dig TXT +short
  • host
  • dig TXT +short | awk -F'"' '{ print $2}'
answered 3 months ago


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 3 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?


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}')
profile pictureAWS
answered 3 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