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? Thanks, JSR/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20110117/e5da9ec3/attachment.htm>
On 18/01/2011, at 7:45 AM, Josiah Ritchie wrote:> 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?Hi Josiah, It should be pretty straight forward to get the MAC addresses of things. The (scripting) approach that's coming to mind, is to first use virsh to get a list of all the domains (using "virsh list --all") or similiar. Then, for each of the domains, run the virsh "dumpxml" command, which includes the MAC address on one of the network device lines. Getting the IP addresses associated with each MAC isn't always quite as easy. It depends on how IP addresses are given to the guests. For example they could be given out via a DHCP server controlled by libvirt. Or they could be given out via a DHCP on a real physical network. (both quite possible) Alternatively, they could be hard coded statically inside each guest (so libvirt doesn't know what it is), or any combination of the above I'm pretty sure there are scripts around, that will help automate the collection of IP addresses for some of these. From memory Richard Jones (on this mailing list already) has a blog entry or two on this subject. He'll probably post a link if my memory isn't being dodgy. :) Does any of that help? Regards and best wishes, Justin Clift
? 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 192.168.122.118 * * == 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 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 e.g. for a guest which use libvirt "default" network, get the subnet like: # 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, :-) Regards Osier> JSR/ > > > > _______________________________________________ > libvirt-users mailing list > libvirt-users at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-users