Changes between Initial Version and Version 1 of find-guest-with-ip


Ignore:
Timestamp:
Jun 9, 2016, 1:51:04 PM (9 years ago)
Author:
Jamie McClelland
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • find-guest-with-ip

    v1 v1  
     1= Find guest that has the given IP address =
     2
     3Sometimes we have an IP address and we want to find out which guest is configured to use it.
     4
     5There are several ways to do this.
     6
     7== dig ==
     8
     9The easiest way is to look for a reverse DNS entry (ptr) using dig:
     10
     11{{{
     120 jamie@turkey:~$ dig +short -x 209.51.172.13
     13chavez.mayfirst.org.
     140 jamie@turkey:~$
     15}}}
     16
     17== Check Puppet ==
     18
     19If that fails and you have access to our [wiki:puppet puppet repository], you can grep the puppet repo:
     20
     21{{{
     220 jamie@turkey:confdir$ grep 209.51.172.13 manifests/nodes/production/*.pp
     23manifests/nodes/production/chavez.pp:  mayfirst::m_interface::set { "209.51.172.13/28": gateway => "209.51.172.1" }
     24manifests/nodes/production/chavez.pp:     address => "209.51.172.13",
     25manifests/nodes/production/parsi.pp:      guest_ipaddress => "209.51.172.13",
     260 jamie@turkey:confdir$
     27}}}
     28
     29These results show that the IP is assigned to chavez (also note that chavez is a guest on parsi).
     30
     31Sometimes 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).
     32
     33= From the host =
     34
     35If all else fails, you can search by MAC address.
     36
     37The 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:
     38
     39{{{
     40ping -c1 209.51.172.13 && arp -an | grep 209.51.172.13
     41}}}
     42
     43The 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.
     44
     45In our case we get:
     46
     47{{{
     48? (209.51.172.13) at 02:c3:88:54:1d:8c [ether] on eth0
     49}}}
     50
     51Now, iterate over all physical hosts and grep the output of ps to find the running kvm instance with a matching mac address.
     52
     53{{{
     54for 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
     55}}}