Linux bonding, vlans, bridges & KVM

In this blog post I’ll share with you how to setup the
networking part of your virtualization solution using KVM.

We will talk about bonding, vlans and bridges.

Setting up a KVM host is an easy one. What people often forget to
think about is the networking part of it. I’m not going to explain
what bonds, vlans and bridges are here - there’s plenty of good
documentation out there which explains it better.

So if you are new to bonds, vlans and bridges I’d suggest you spend
some time checking the links below:

The target system I’m using as a KVM hypervisor is Debian Wheezy,
which is already configured for hosting KVM guest domains. The last
thing that remains is to configure the networks for the KVM guests.

The networking setup of the KVM hypervisors we have is more-or-less
described like this. First we configure bonding on the interfaces for
link aggregation and failover, then we create VLANs of the bond for
splitting the network into logical segments for our VMs, and lastly we
configure bridges of the VLANs, which will be attached to the running
KVM guest domains.

So, lets start, shall we? Install First, lets install some packages:

$ sudo apt-get install ifenslave-2.6 vlan bridge-utils

Then we create two bonding interfaces - bond0 and bond1 and put
our networking configuration in /etc/network/interfaces, which looks
like this:

The reason we create VLANs is because we want to have different
networks for our VM machines - test network, engineering, production,
etc. Out of the VLANs we create bridges as well, so that we can attach
our KVM VMs to them.

Once you are ready you can restart the network or reboot your machine
in order to apply the changes. Once the changes are in place you can
check the status of your bonds in /proc/net/bonding*, e.g.: