[libvirt-users] list mac or IP of all guests NICs?

Osier Yang jyang at redhat.com
Tue Jan 18 09:01:17 UTC 2011

于 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/.* 

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, :-)


> JSR/
> _______________________________________________
> libvirt-users mailing list
> libvirt-users at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-users

More information about the libvirt-users mailing list