Edit: Everything described here can be accomplished in the Virtual-Manager GUI, but this is here for all the CLI junkies.
I decided to take the time to write up a quick HowTo for configuring RHEL 6 or any of it’s clones (CentOS 6 and Scientific Linux to name a couple) so that KVM can use your main network device for bridged connections on your VMs. Some virtualization solutions make bridge connections pretty simple and automatic. KVM requires (from everything I’ve seen at least) a little more hands-on configuration.
I’ve collected this information from various sources. One of the things I’ve noticed is that most sources advise you to stop the NetworkManager service and to disable it at boot. I agree with this as we are going to be doing more advanced configurations of our network devices and automated tools like NetworkManager are best for more basic setups where the user doesn’t want to fiddle with the configurations manually. So you’ll want to do the following as root:
chkconfig NetworkManager off chkconfig network on service NetworkManager stop service network start
In this example I’ll be using eth0 as my physical network device. You may be using eth1 or some other device. Make sure to replace eth0 with your actual network device. In most cases it is eth0.
ifdown eth0Now create a bridge device. We are going to call it bridge0. If you’ll notice in /etc/sysconfig/network-scripts you’ll see configuration files for your network devices. You should see one for eth0. It will be called ifcfg-eth0. Edit that file. If you use a static IP address you’ll actually set that up in the bridge0 device configuration file later. Change the ifcfg-eth0 file to look like this (leave the HWADDR line alone, I’m leaving it out of the below example because it will be different on each machine):
DEVICE="eth0" BOOTPROTO="none" NM_CONTROLLED="yes" ONBOOT="yes" BRIDGE="bridge0"
Now we have told eth0 to use the bridge “bridge0″. We now need to create the configuration file for that bridge. Edit/Create the file /etc/sysconfig/network-scripts/ifcfg-bridge0 and add these lines:
DEVICE="bridge0" TYPE="Bridge" BOOTPROTO="static" ONBOOT="yes" DELAY=0 IPADDR=192.168.1.5 GATEWAY=192.168.1.1 DNS1=192.168.1.1
Save it and let’s start eth0 back up along with the new bridge:
ifup eth0 ifup bridge0
Now if you look at an ifconfig your bridge device will have your static IP of 192.168.1.5 (you can change this to your own static IP of course). Now in your KVM virtual machine manager, you’ll be able to use bridge0 as your bridge network device. Any VM that connects to that bridge will be able to get a DHCP IP address from the router or it can be configured with a static IP.
Be wary of Firewall rules on the host machine. Check those first if you have any access issues on the guest.
Questions/Comments are welcome.