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

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

Schreibe einen Kommentar