Thanks Justin and Osier. I had searched for a leases file on the machine before, but couldn't find it so thank you for pointing that out. I had thought about installing nmap, but figured I had to have some better record on the machine itself.

Thanks also for the tip on Rich's blog post. I found it at


On Tue, Jan 18, 2011 at 4:01 AM, Osier Yang <> wrote:
于 2011年01月18日 04:45, Josiah Ritchie 写道:

I'm trying to figure out how to use virsh (or something else) to list
all the IP addresses (or MAC addresses if needed) for each virtual NIC,
preferably with it domain affiliation also listed.

Is this possible?

== method 1: (simple but not reliable)
# cat /var/lib/dnsmasq/dnsmasq.leases
1295343272 52:54:00:6f:2e:72 * *

== method 2:
# This script is to map MAC into IP, accepts two
# arguments, subnet prefix and MAC address of the
# interface.
#! /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

e.g. for a guest which use libvirt "default" network, get the subnet
# ip route | grep "virbr0" | sed -n 1p | awk '{print $1}'

you could write automate script to parse the MAC address of domain
interfaces, the bridge name, and the subnet prefix of bridge, and
then use the script above the get the IP.

And as Justin said, Rich has more clever tool to do it, I also forgot,
you can wait him, :-)



libvirt-users mailing list

libvirt-users mailing list