Re: question on kvm

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As usual, you can try the following methods:

1. log in the guest then ifconfig
I guess it's not what you want

2. filter /var/lib/dnsmasq/dnsmasq.leases file 
according to actual guest mac address

3. using nmap to scan guest subnet
paste the following shell codes into mac2ip.sh:

#! /bin/bash

if [ $# -ne 2 ]; then
    echo "Usage: $(basename $0) <SUBNET> <MAC>" 
    exit 1
fi

SUBNET=$1
MAC=$2

rpm -q nmap > /dev/NULL
if [ $? -ne 0 ]; then
    echo "you need install nmap"
    exit 1
fi

if [[ -n $SUBNET ]]; then
   OUTPUT=$(nmap -sP -n $SUBNET | grep -i -B 2 $MAC)
   if [[ -n $OUTPUT ]]; then
      IP=$(echo $OUTPUT | sed -e 's/.* \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/')
   fi
fi

echo $IP

And then run the following cmdline:

% mac=$(virsh dumpxml ${your domain name} | grep "mac address" | awk -F"'" '{print $2}' | head -1)
% subnet=$(ip route | grep "${your guest interface}" | sed -n 1p | awk '{print $1}')
% sh mac2ip.sh $subnet $mac

Note: for instance, your guest name is 'foo', and interface is 'virbr0'


Good Luck!
Alex

----- Original Message -----
From: "hero" <515801610@xxxxxxx>
To: "libvir" <libvir-list@xxxxxxxxxx>
Sent: Thursday, December 22, 2011 9:20:56 AM
Subject:  question on kvm




on redhat5.6 and redhat 6.1, I can got the MAC address of the kvm VMs,but I don't know how to get the ip address of the VMs,and virsh has not got a command,can you help me to resolve it. 


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]