Archiv für Juni, 2014

Linux KVM Print mapping between virtual interfaces (vnet) and virtual machines

3. Juni 2014 Keine Kommentare

To print the actual mapping between the virtual interfaces (vnet0 – vnetXY) and the running virtual machines you can use the following command. It should work on all Linux distributions running KVM and libvirt.

for vm in $(virsh list | awk '{if ((NR >= 3) && (NF >=1)) print $2}'); do vm_config=$(virsh dumpxml $vm); for iface in $(sed -n -r 's/.*(vnet[0-9]{1,}):.*/\1/p' /proc/net/dev); do echo "$vm_config" | grep -q "'${iface}'" && echo "${vm}: ${iface}"; done; done