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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠