loading...

How to get the details which Instance is using particular Elastic IP (EIP)

dineshrathee12 profile image Dinesh Rathee ・4 min read

Scenario:
How to get the details of Instance using particular Elastic IP (EIP) - How to get the details of Instance using particular Elastic IP (EIP).

For example:
I have an EIP with me and I don't know where its located ?

Answering to - "I don't know where its located" :

  • You can use "nslookup" or "dig -x" command to check the "aws region" where EIP is located.

Example:

# dig -x 52.37.109.242 +short
ec2-52-37-109-242.us-west-2.compute.amazonaws.com.
C:\Users\administrator> nslookup 52.37.109.242
Server:  recycled-xxxxxxxxxx.xxxx
Address:  xx.xx.xx.xx
Name:    ec2-52-37-109-242.us-west-2.compute.amazonaws.com
Address:  52.37.109.242

This confirms the association of domain with EIP and region of the resource is

(us-west-2)

Now, Let's figure out where or to which instance it has been attached to ??
==========================================================
The only way to get the details of EIP address associated with your Instance in a particular account is to login in the existing account and check it and you have two methods to do so:

1). Using console:-

  • Go to EC2 - Navigate to "Elastic IP" section on left or click here
  • Then you can see the EIP details and associations with an Instance. For more details , please check :

[+] https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html
[+] https://aws.amazon.com/premiumsupport/knowledge-center/vpc-find-owner-unknown-ip-addresses/

2). Using AWS CLI:-
You can use CLI command with API's (describe-addresses & describe-instances) to get the details of an EIP and its associations. I'm providing you an example below which you can refer.

Note : Please make sure you replace the EIP & Region details according to your resources where they are located in.

I've tested this as follows:

➜ Using (describe-addresses) you can get the info : ( AWS CLI command below)

# aws ec2 describe-addresses --public-ips YourEIPAddressHere --region us-west-2 --query "Addresses[].[PublicIp,PrivateIpAddress,InstanceId,AllocationId,AssociationId]" --output table

Example:

# aws ec2 describe-addresses --public-ips 52.37.109.242 --region us-west-2 --query "Addresses[].[PublicIp,PrivateIpAddress,InstanceId,AllocationId,AssociationId]" --output table
----------------------------------------------------------------------------------------------------------------------
|                                                  DescribeAddresses                                                 |
+---------------+---------------+----------------------+------------------------------+------------------------------+
52.37.109.242|  172.xx.xx.xx |  i-0axxxxxxxxxxxeipalloc-0fxxxxxxxxx  |  eipassoc-08xxxxxxxx  |
+---------------+---------------+----------------------+------------------------------+------------------------------+

Also,
➜ Using (describe-instances) you can get the info : (AWS CLI command below)

# aws ec2 describe-instances --region us-west-2 --filter Name="ip-address",Values="YourEIPAddressHere" |grep 'InstanceId\| YourEIPAddressHere'

Example:

# aws ec2 describe-instances --region us-west-2 --filter Name="ip-address",Values="52.37.109.242" |grep 'InstanceId|52.37.109.242'
                    "InstanceId": "i-0axxxxxxxxxxx",
                    "PublicDnsName": "ec2-52-37-109-242.us-west-2.compute.amazonaws.com",
                    "PublicIpAddress": "52.37.109.242",
                                "PublicDnsName": "ec2-52-37-109-242.us-west-2.compute.amazonaws.com",
                                "PublicIp": "52.37.109.242"
                                        "PublicDnsName": "ec2-52-37-109-242.us-west-2.compute.amazonaws.com",
                                        "PublicIp": "52.37.109.242"

To know more on filters , you can refer to our CLI reference guide on these APIs.

[+] describe-instances :- https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html

[+] describe-addresses :- https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-addresses.html

Thanks
Dinesh Rathee

Posted on by:

dineshrathee12 profile

Dinesh Rathee

@dineshrathee12

Dinesh Rathee , Young IT Professional 💻 Working in Dublin (Ireland) 💚 Enthusiast, Innovative, Loves Travelling 🛣 & Exploring ⛰🚵‍♂ #Fan of @elonmusk 🚀🛰, Proud Son👨‍🎓with Big Dreams.🏁

Discussion

markdown guide