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

Re: [libvirt] question on kvm

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


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

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/')

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!

----- Original Message -----
From: "hero" <515801610 163 com>
To: "libvir" <libvir-list redhat com>
Sent: Thursday, December 22, 2011 9:20:56 AM
Subject: [libvirt] 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 redhat com

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