DEV Community

Dinesh Rathee
Dinesh Rathee

Posted on • Updated on

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

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.xxxxxxxx +short
ec2-52xxxxxxxxxxxus-west-2.compute.amazonaws.com.
C:\Users\administrator> nslookup 52.xxxxxxxxxxx
Server:  recycled-xxxxxxxxxx.xxxx
Address:  xx.xx.xx.xx
Name:    ec2-52-xxxxxxxxxxx.us-west-2.compute.amazonaws.com
Address:  52.xxxxxxxx

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
Enter fullscreen mode Exit fullscreen mode

Example:

# aws ec2 describe-addresses --public-ips 52.xxxxxxxxx --region us-west-2 --query "Addresses[].[PublicIp,PrivateIpAddress,InstanceId,AllocationId,AssociationId]" --output table
----------------------------------------------------------------------------------------------------------------------
|                                                  DescribeAddresses                                                 |
+---------------+---------------+----------------------+------------------------------+------------------------------+
52.xxxxxxxxxxxxx|  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'
Enter fullscreen mode Exit fullscreen mode

Example:

# aws ec2 describe-instances --region us-west-2 --filter Name="ip-address",Values="52.xxxxxxxxxxxxxxx" |grep 'InstanceId|52.xxxxxxxxxxxx'
                    "InstanceId": "i-0axxxxxxxxxxx",
                    "PublicDnsName": "ec2-52-xxxxxxxxxxx.us-west-2.compute.amazonaws.com",
                    "PublicIpAddress": "52.xxxxxxxxxxxxx",
                                "PublicDnsName": "ec2-52-xxxxxxxxxxx.us-west-2.compute.amazonaws.com",
                                "PublicIp": "52.xxxxxxxxxxxxxxxxxx"
                                        "PublicDnsName": "ec2-52-xxxxxxxxxxx.us-west-2.compute.amazonaws.com",
                                        "PublicIp": "52.xxxxxxxxxxxxxx"

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

Oldest comments (0)