KVM guest virtual network configuration using MacVTap

KVM guest definitions that dictate how a KVM guest is configured are performed from within the KVM host environment. KVM guest definitions are specified using an XML file that is processed by the libvirtd daemon. The XML file specifies most of the hardware configuration characteristics of the KVM guest including the virtual network descriptions.

To configure a KVM guest network interface to use the MacVTap driver, the XML stanza to define the KVM guest's interface in the guest's libvirt XML configuration file should include the following:

<interface type="direct">
  <mac address="12:34:56:78:9a:bc"/>   
  <source dev="o5s_10g_1" mode="bridge"/> 
  <model type="virtio"/> 
  <driver name="vhost"/> 
</interface>
The relevant xml tags here are:
<interface type="direct">
Used for MacVTap; specifies a direct mapping to an existing KVM host device.
<source dev="kvm-host-device" mode="bridge">
Specifies the KVM host network interface name that will be used by the KVM guest's MacVTap interface. The mode keyword defines which MacVTap mode will be used.

The MAC address field is optional; if it is omitted, the libvirt daemon will generate a unique address.

After the changes have been saved in the KVM guest's libvirt xml configuration file, the libvirt daemon needs to be informed, using the following commands:

[root@kvmhost ~]# virsh undefine <kvm-guest-name>
[root@kvmhost ~]# virsh define <kvm-guest-libvirt-xml-file>

A KVM guest definition can only be added when the KVM guest is not running.

Lastly, remember to restart the KVM guest for the changes to take effect. The defined MacVTap interface will be persistent and automatically started whenever the KVM guest restarts.