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.


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

0 jamie@turkey:~$ dig +short -x
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 manifests/nodes/production/*.pp
manifests/nodes/production/chavez.pp:  mayfirst::m_interface::set { "": gateway => "" }
manifests/nodes/production/chavez.pp:	  address => "",
manifests/nodes/production/parsi.pp:      guest_ipaddress => "",
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, you might also get, 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 && arp -an | grep

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:

? ( 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@$ "ps -eFH | grep [mac]=02:c3:88:54:1d:8c"; done
Last modified 5 years ago Last modified on Jun 9, 2016, 9:51:04 AM