Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I find the IP of the VM on KVM(using Nmap)? If not,are there any functions in Libvirt to do that?

share|improve this question
    
Answer: After a day's worth of trying nmap/ifconfig/iptables, I chanced to stumble upon this - rwmj.wordpress.com/2010/10/26/…. epic link. –  P Ramesh Sep 9 '11 at 20:23
add comment

migrated from stackoverflow.com Sep 9 '11 at 17:46

This question came from our site for professional and enthusiast programmers.

2 Answers

Fast and dirty example for KVM on Centos 63 x86_64. Short ping in background to all possible IP addresses that the VMs may have in this segment

for i in {1..249}
 do
  ping -c 1 -n -q -r  -t 1 -s 1  -W 1   192.168.100.$i > /dev/null &
done

Extract the names and MAC addresses of the VMs via virsh and extract IP from ARP table

for name in `virsh list | grep running | awk '{ print $2 }'`
do
  printf  "\n$name\n "
  arp -e | grep "`virsh dumpxml  $name | grep "mac address"|sed "s/.*'\(.*\)'.*/\1/g"`" | 
  awk '{ printf  $1 ;  printf  " "  ; printf  $3 }'
done
share|improve this answer
add comment
up vote 2 down vote accepted

After long hours of getting my hands dirty, I chanced to stumble upon this Epic link.

  1. Get the MAC address of the VM from the config file of the VM(since I'm using KVM, I queried the .xml file for the MAC address).
  2. Then use arp -a and get all the the MAC addresses and the Address of the interfaces and store it in a file
  3. Query the file for the MAC address of VM from step 1.
share|improve this answer
    
Could you describe how this solved your problem? What did you do exactly? –  Simon Sheehan Sep 9 '11 at 20:26
    
@Simon Sheehan- Here's how I did it- 1. get the MAC address of the VM from the config file of the VM(since I'm using KVM, I queried the .xml file for the MAC address). 2. Then use arp -a and get all the the MAC addresses and the Address of the interfaces and store it in a file 3.query the file for the MAC address of VM from step 1. –  P Ramesh Sep 9 '11 at 20:56
    
Great, I added that to your answer –  Simon Sheehan Sep 9 '11 at 21:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.