- Newest
- Most votes
- Most comments
Hi,
So, can we know if elastic IP is public or not?
Additionally, I also tried to set the private IP with which to associate the elastic IP address, but it only assigned the public IP as the elastic IP.
An elastic IP address is always a public IP address, and it can never be set to a private IP address.
An Elastic IP address is a static, public IPv4 address designed for dynamic cloud computing.
https://docs.aws.amazon.com/vpc/latest/userguide/vpc-eips.html
I want to differentiate between elastic IP and public IP
If you want to know if your current public IP is an elastic IP or an auto-assigned public IP, you need to check the Elastic Network Interface (ENI) attached to the EC2 instance.
For example, we found the instance named EC2Instance1
has an elastic IP address associated.
$ aws ec2 describe-instances --filters Name=tag:Name,Values=EC2Instance1 Name=instance-state-name,Values=running --query Reservations[0].Instances[0].NetworkInterfaces[0].NetworkInterfaceId --output text eni-02884be02dc04f331 $ aws ec2 describe-network-interfaces --filters Name=network-interface-id,Values=eni-02884be02dc04f331 --query NetworkInterfaces[0].Association { "AllocationId": "eipalloc-04e4114f3e6d3de03", "AssociationId": "eipassoc-02bcdbc1de7971421", "IpOwnerId": "512667299293", "PublicDnsName": "ec2-46-51-254-206.ap-northeast-1.compute.amazonaws.com", "PublicIp": "46.51.254.206" }
On the other hand, instance EC2Instance2
has no EIP association, so its public IP is an auto-associated one.
$ aws ec2 describe-instances --filters Name=tag:Name,Values=EC2Instance2 Name=instance-state-name,Values=running --query Reservations[0].Instances[0].NetworkInterfaces[0].NetworkInterfaceId --output text eni-014807097783ee2f7 $ aws ec2 describe-network-interfaces --filters Name=network-interface-id,Values=eni-014807097783ee2f7 --query NetworkInterfaces[0].Association { "IpOwnerId": "amazon", "PublicDnsName": "ec2-54-168-239-42.ap-northeast-1.compute.amazonaws.com", "PublicIp": "54.168.239.42" }
Instead of checking programmatically, of course, you can use AWS Console to check for ENI and EIP association in the same manner.
Relevant content
- asked 2 years ago
- asked 4 months ago
- asked a year ago
- AWS OFFICIALUpdated a month ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a month ago
- AWS OFFICIALUpdated a year ago
Thank you so much !