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!!
How about this (example for
vnet13
):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. WhichvnetX
interface is attached to which VM is such a dynamic property. Same goes for the VM's MAC addresses.Try
virsh dumpxml $domain
, you'll see something like:the
alias name
is what is used in the qemu-kvm command line, so if you runps -ef |grep qemu|grep net1
from my example, you will see the actual command syntax used for this interface.Run
virsh domiflist myVM
. This command will list all the interfaces related to VM myVM.Every one of the solutions given above assumes that the VMs are being managed by libvirt. It is quite possible to run QEMU VMs without that, in which case you cannot use virsh or look at XML to find the answer.
In the case of running QEMU VMs from a "raw" command line:
tcpdump -i tap0 -f 'icmp' (substitute whichever tap interface you're interested in)
Ping each candidate VM until you see packets in the trace. The interface you are tracing when ICMP packets appear is the one you're looking for!
Conversely you can start a ping to a particular VM and then tcpdump each tap interface in turn until one "lights up". Depends whether you're interested in finding the VM that matches the tap interface, or the tap interface that matches the VM.
Match IP Addresses from Arp cache to VM
Sample output:
Based on @daff response:
Output Example:
The MAC address of the
vnetX
interfaces belongs to the host, not the guest.brctl showmacs br0
will show the MACs detected by the bridge, but you'd then need to cross reference the port number with the list of interfaces frombrctl show
.Example output:
This will list all running VMs along with their interfaces: