Can we know if the public is elastic or not?

0

Actually, I want to differentiate between elastic IP and public IP, but as we know, when we bind an elastic IP to an instance, public-ipv4 is the address of the elastic IP.

Ref: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html Enter image description here

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.

Enter image description here

profile picture
asked 7 months ago365 views
1 Answer
2
Accepted Answer

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.

profile picture
HS
answered 7 months ago
  • Thank you so much !

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