Using a Linux Bridge
An alternative to using a NAT-based network would be to use a standard Linux® network bridge.
A network bridge is a Link Layer device which forwards traffic between networks based on MAC addresses and is therefore also referred to as a Layer 2 device. It makes forwarding decisions based on tables of MAC addresses which it builds by learning what hosts are connected to each network. A software bridge can be used within a Linux host in order to emulate a hardware bridge, for example in virtualization applications for sharing a NIC with one or more virtual NICs.1
In the context of KVM, a Linux bridge is used to connect the KVM guest interface to a KVM host network interface.
[root@kvmhost ~] # brctl addbr <bridge-name>
[root@kvmhost ~] # brctl addif <bridge-name> <host-interface-name>
- By registering the bridge device with the OSA card.
- By configuring the OSA card for Bridgeport mode and enabling promiscuous mode in the KVM host kernel.
<interface type=bridge
>
<mac address=11:22:33:44:55:66
/>
<source bridge=bridge-name
/>
<model type=virtio
/>
<driver name=vhost
/>
</interface>
For a KVM guest interface to connect to a
bridge, use <interface type=”bridge”>
and specify the name of the bridge using
the <source bridge=
keyword.
For better performance throughput and latency, it is recommended that KVM guests use the newer
vhost-net
driver, rather than the older para-virtualized
virtio-net
driver, by specifying the keyword <driver
name="vhost"/>
in the guest's libvirt configuration file. vhost-net
uses an in-kernel guest networking performance enhancement which moves network packets between the guest and the host system using the Linux kernel rather than QEMU. This avoids context switches from the kernel to user space to improve overall performance.
The MAC address field is optional and if omitted, the libvirt daemon will generate a unique value.
[root@kvmhost ~] # virsh undefine <kvm-guest-name>
[root@kvmhost ~] # virsh define <kvm-guest-libvirt-xml-file>
And finally, remember to restart the KVM guest for the changes to take affect.