- Newest
- Most votes
- Most comments
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}'
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:
Category | Description | Version when category was released |
---|---|---|
public-ipv4 | The 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! :)
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}')
curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/${myMacAddress}/ipv4-associations/
Relevant content
- asked a year ago
- asked 3 years ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago
Have you been able to resolve your issue? If so, would you select an answer that matched your issue to close out the thread?