Way to determine which virtual interface belongs to a virtual machine in a kvm host

bridgekvm-virtualizationnetworkingqemu

I'm using qemu/kvm whith bridged networking. In the host machine there are several "vnetX" network interfaces without IP. I'm looking for a way to know which vnetX belong to a virtual machine.

I tried to match the MAC Address values on these interfaces with the MACs on the virtual machines (or the XML which defines them), but doesn't match.

There's brctl show which shows the vnet interfaces that belongs to a bridge, but this is not useful info.

Is there a way to know that relation? Thx!!

Best Answer

How about this (example for vnet13):

$ VNET=vnet13; for vm in $(virsh list | grep running | awk '{print $2}'); do virsh dumpxml $vm|grep -q "$VNET" && echo $vm; done

Here we use virsh dumpxml to show dynamic properties about the VM, which are not available in the static XML definition of the VM in /etc/libvirt/qemu/foo.xml. Which vnetX interface is attached to which VM is such a dynamic property. Same goes for the VM's MAC addresses.