Friday, February 10, 2012

Finding out the KVM client IP address, without running virt-manager

Problem:
In RedHat, how do you find out the IP address of KVM client from the hypervisor it's running on, without starting virt-manager?

Solution:
From the kvm host or hypervisor, use "virsh dumpxml [servername]" to get the kvm client MAC address & the network interface its using. Then use "arp" or "tcpdump" to get its IP address.

Procedure:
1. Login to the kvm host/hypervisor and issue the command: virsh dumpxml [server name].

Example: virsh dumpxml test1-server

2. From the xml output, look for the MAC address & interface entry, which looks something like this:


3. Use "arp -a" to query for the IP address.

[testuser@test1-server ~]$ arp -a
test-client1.apollo.com (192.168.1.120) at 63:54:00:3f:46:5a [ether] on br0
test-client2.apollo.com (192.168.1.125) at 63:54:00:bb:e7:90 [ether] on br0
test-client3.apollo.com (192.168.1.9) at 01:25:45:b3:6d:84 [ether] on br0

4. If "arp -a" does not match the xml MAC address you're looking for, use the old reliable "tcpdump".

[testuser@test1-server ~]$ sudo tcpdump -vv -i br0 | grep 63:54:00:49:f4:87
tcpdump: listening on br0, link-type EN10MB (Ethernet), capture size 65535 bytes
12:31:08.887230 ARP, Ethernet (len 6), IPv4 (len 4), Reply 192.168.1.118 is-at 63:54:00:49:f4:87 (oui Unknown), length 28
12:32:08.000218 ARP, Ethernet (len 6), IPv4 (len 4), Reply 192.168.1.118 is-at 63:54:00:49:f4:87 (oui Unknown), length 28
12:32:32.121785 ARP, Ethernet (len 6), IPv4 (len 4), Reply 192.168.1.118 is-at 63:54:00:49:f4:87 (oui Unknown), length 28


Reference:
http://rwmj.wordpress.com/2010/10/26/tip-find-the-ip-address-of-a-virtual-machine/