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