It may be desirable to pass VLAN traffic from a virtual machine out to the wider network. This tutorial assumes that you have configured the guest to connect to the host using a bridge interface, e.g. br0 (instructions here). Please Note: The default KVM/QEMU virtual network card, rtl8139, DOES NOT support VLANs (802.1q) (reference 1, reference 2). To use VLANs with the guest, you must use the virtio virtual network interface in your KVM configuration.
The easiest way to set this up is to use the same network bridge for all traffic, but to tag the VLAN traffic inside the VM. In this example, we will create an interface for VLAN 6.
On the VM:
1 2 3 |
# modprobe 8021q # vconfig add eth0 6 # ifconfig eth0.6 192.168.1.12 netmask 255.255.255.0 up |
This will create a new interface, eth0.6, where you can send the VLAN traffic. Both VLAN traffic (over eth0.6) and regular traffic (over eth0) will pass over br0 on the host to the rest of the network.
To make these settings permanent on Debian/Ubuntu, do to the following:
- add 8021q to /etc/modules
- add the following section to /etc/network/interfaces:
1 2 3 4 5 6 |
## VLAN Configuration auto eth0.6 iface eth0.6 inet static address 192.168.1.12 netmask 255.255.255.0 vlan_raw_device eth0 |
To make these settings permanent on RHEL/CentOS, do to the following:
- echo modprobe 8021q >> /etc/rc.modules && chmod +x /etc/rc.modules
- Follow the instructions outlined here and make sure your ifcfg-eth0.6 looks similar to this:
1 2 3 4 5 6 7 |
DEVICE=eth0.6 VLAN=yes BOOTPROTO=none NETMASK=255.255.255.0 IPADDR=192.168.1.12 ONBOOT=yes HWADDR=00:01:02:03:04:05 |
Your VM should now be configured to handle VLAN 6 traffic over eth0.6 and pass it along to the host over br0. You can verify that the VLAN traffic is present by running tcpdump -i br0 on the host.





