wiki:find-guest-with-ip

Find guest that has the given IP address

Sometimes we have an IP address and we want to find out which guest is configured to use it.

There are several ways to do this.

dig

The easiest way is to look for a reverse DNS entry (ptr) using dig:

0 jamie@turkey:~$ dig +short -x 209.51.172.13
chavez.mayfirst.org.
0 jamie@turkey:~$ 

Check Puppet

If that fails and you have access to our puppet repository, you can grep the puppet repo:

0 jamie@turkey:confdir$ grep 209.51.172.13 manifests/nodes/production/*.pp
manifests/nodes/production/chavez.pp:  mayfirst::m_interface::set { "209.51.172.13/28": gateway => "209.51.172.1" }
manifests/nodes/production/chavez.pp:	  address => "209.51.172.13",
manifests/nodes/production/parsi.pp:      guest_ipaddress => "209.51.172.13",
0 jamie@turkey:confdir$

These results show that the IP is assigned to chavez (also note that chavez is a guest on parsi).

Sometimes the grep will show more results than you expect (for example if you search for 209.51.172.1, you might also get 209.51.172.12, 209.51.172.13 etc).

From the host

If all else fails, you can search by MAC address.

The first step is to determine the MAC address of the IP address. You can find that out by running the following command from any server in the same subnet:

ping -c1 209.51.172.13 && arp -an | grep 209.51.172.13

The first command sends a ping to the IP address (which will fill the arp table on the host) and the second command gets a listing of the arp table and filters by the IP address we are looking for.

In our case we get:

? (209.51.172.13) at 02:c3:88:54:1d:8c [ether] on eth0

Now, iterate over all physical hosts and grep the output of ps to find the running kvm instance with a matching mac address.

for foo in $(freepuppet-helper ls:m_physical); do echo $foo && ssh root@$foo.mayfirst.org "ps -eFH | grep [mac]=02:c3:88:54:1d:8c"; done
Last modified 3 years ago Last modified on Jun 9, 2016, 9:51:04 AM