Categories
How-To's

Gentoo KVM virtual machine support plus networking

The Gentoo Wiki article about KVM uses the less flexible networking setup with dedicated TAP devices like ‘tap0’. While this setup works fine, other distributions use the bridge device in a different way. By creating a virtual bridge and forcing the host system to connect through this bridge, virtual machines can simply connect to the bridge device and ‘plug in’. No need to manually create TAP devices. In this guide we will set up host and guest networking using the virtual bridge device and DHCP for wired ethernet.

Categories
Linux / Gentoo Linux

Networking for KVM with CentOS 5.5

I’ve found numerous tutorials to set up KVM with CentOS 5.5. Some refer to the Red Hat guides, which are useless in my opinion if you are not using KVM in a large server park, others come up with scripts to set up networking.

I kept searching and trying configurations until I finally found one that works. Note that among problems you might encounter is the one that plagued me for months: CentOS is attempting to bring up the virtual device for LAN access on the host before bringing up the physical interface, this fails and prevents all networking and dependencies from starting properly.

To set up the bridge devices for KVM and the host (something which is done only once to ‘wire’ your virtual network instide the bridge) look here. Most of the guide is still relevant even if they refer to the Red Hat documentation (which is about Red Hats cloud virtualisation platform and not a single server running KVM).

Use a configuration like this for proper KVM networking under CentOS, Red Hat and probably even Fedora.

1. Edit /etc/sysconfig/network-scripts/ifcfg-eth0 to contain something like this:

1
2
3
4
5
6
7
# /etc/sysconfig/network-scripts/ifcfg-eth0 - the physical NIC which will not be used directly
DEVICE=eth0
TYPE=Ethernet
HWADDR=00:23:B3:16:3F:00
ONBOOT=yes
BRIDGE=br0
NM_CONTROLLED=no

The “NM_CONTROLLED” bit seems to originate from Fedora 12/13, CentOS might ignore it altogether so you could leave it out.

2. Edit /etc/sysconfig/network-scripts/ifcfg-br0 to restore network access for your host machine:

1
2
3
4
5
6
# /etc/sysconfig/network-scripts/ifcfg-br0 - Bridged network access for host
DEVICE=br0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes
NM_CONTROLLED=no

The crucial parts in this configuration is that eth0 is started on boot and is assigned a bridge device: ‘br0’. The ‘br0’ device is marked as a bridge device which completes the dependencies between them. So make sure if you deviate from the examples you leave the types and ‘bridge=br0’ in tact.