Pass VLAN traffic to KVM Guests

Recently, I was working on a setup where we need to use two IP ranges for KVM guests and we found that VLAN tagging is the best way to achieve this.
Refer the below diagram for more understanding:

To allow Linux host to be aware of VLAN’s we need to enable 802.1Q tagged queuing:

We can do that using modprobe command as:

modprobe 8021q

This should enable the 802.1Q tagged queuing.

To verify if it’s working you can use the command:

# lsmod | grep 8021q
8021q 21768 0

Now, we know that host can recognize VLAN’s.

Next step is to add network interfaces bind to specific VLAN  in our host.

We have eno1 interface in our host and it needs to use tagged network traffic for VLAN ID 1,2.

eno1 – regular network interface

eno1.1 – virtual interface that use untagged frame from VLAN 1

eno1.2 – virtual interface that use untagged frame from VLAN 2

Now we need to configure eno1.1 interface as:

# vi /etc/sysconfig/network-scripts/ifcfg-eno1.1

In this file we write:

DEVICE=eno1.1

VLAN=yes

ONBOOT=yes

TYPE=Ethernet

Save and Quit.

For eno1.2 perform the same steps as above.

Now we need to create a bridge interface that will allow us to bridge network VLAN1 to our guest.

To create a bridge execute the below command:

# brctl addbr br1

Now associate br1 with VLAN1 which is configured on eno1.1

# brctl addif br1 eno1.1

Now, we need to edit the configuration  of our newly created bridge :

# vi /etc/sysconfig/network-scripts/ifcfg-br1

DEVICE=br1

TYPE=Bridge

BOOTPROTO=none

ONBOOT=yes

DELAY=0

Save and quit

Now, we should associate eno1.1 to  br1

# vi /etc/sysconfig/network-scripts/ifcfg-eno1.1

and we add this line:

BRIDGE=br1

So, now it will look like

DEVICE=eno1.1

VLAN=yes

ONBOOT=yes

BRIDGE=br1

TYPE=Ethernet

To apply changes in network configuration, we have to restart network service:

# /etc/init.d/network restart

That’s it, now you have successfully configured VLAN1, follow the same steps for VLAN 2.

Now, all you have to do is to assign br1 as network device to your guest machine and restart the guest machine.

Comments are closed.