Written By James Ravenscroft
Over the last couple of years, I have used both VirtualBox and VMWare server under Linux, but have not been fully satisfied with either one. I have had problems with VirtualBox or a guest OS intermittently crashing and guest OS video display issues. VMWare’s web interface is cumbersome and problematic. Its web service dies inexplicably and I have found myself having to completely reinstall VMWare server after upgrading my kernel.
I decided recently to try AQEMU, a GUI front end to QEMU (and KVM) to set up a simple lab where I can load virtual machines and have them all be on the same network segment as the host machine. I quickly found that in order to do this, you need to enable bridging and then create virtual ethernet “tun/tap” interfaces for each of your guest OS to use. Unfortunately, this was not straightforward and required some searching and package installation/configuration. A synopsis of the steps using Ubuntu 10.4 is below.
1)
Check to make sure all necessary packages are installed and install missing packages. The packages you need are AQEMU, bridge-utils and uml-utlilities. These can all be installed by issuing the following command in a terminal window (with a space between each of the package names) which will download and install all necessary packages:$sudo apt-get install aqemu bridge-utils uml-utilities
2) Check for /dev/net/tun and if not present, load tun using
$sudo /sbin/modprobe tun
3) Add qemusers group and add your user account to the group (so that qemu will not run as root)
$sudo addgroup qemusers
$sudo adduser <user> qemusers
4) Edit /etc/rc.local to make /dev/net/tun usable for the qemusers group per bold text below. Ownership of tun reverts back to root when you reboot and this corrects ownership so that you will be able to use tun. I like using the Gedit text editor:
$sudo gedit /etc/rc.local
==================
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Set permissions of tun device
chown root.qemusers /dev/net/tun
chmod g+rw /dev/net/tun
exit 0
==================
5) Edit /etc/network/interfaces to set up the bridge, create tap interfaces and join eth0 and all the tap interfaces to be used by your virtual machines to the bridge. An example of this is below; this creates and initializes 3 tap interfaces, a bridge (with static IP) and joins eth0 and tap0-2 to the bridge. The tunctl_user listed should be a valid user that is also a member of the qemusers group (step 3 above). You will want to initialize as many tap interfaces as the maximum number of virtual machines that you will want to run at any given time. Alternatively, you could just include the information to set up the bridge (and add eth0 to it) only and create scripts to initialize tap interfaces and join them to the bridge as needed:
$sudo gedit /etc/network/interfaces==================
auto lo
iface lo inet loopback
iface eth0 inet manual
auto tap0 tap1 tap2
iface tap0 inet manual
tunctl_user <user>
iface tap1 inet manual
tunctl_user <user>
iface tap2 inet manual
tunctl_user <user>
auto br0
iface br0 inet static
bridge_ports eth0 tap0 tap1 tap2
bridge_maxwait 0
address 192.168.1.60
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
All that’s left is to reboot and configure your guests, which I’ll show in my next post. Have a safe and Happy New Year!
Useful links:
Linux bridging: http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge
Tun/Tap Wiki:http://en.wikipedia.org/wiki/TUN/TAP
QEMU Wiki:http://en.wikipedia.org/wiki/QEMU
QEMU bridge/interface configuration:
http://wiki.freaks-unidos.net/qemu-debian
http://compsoc.dur.ac.uk/~djw/qemu.html
http://www.thomaskho.com/blog/2006/02/qemu-and-the-network-bridge/
AQEMU: http://sourceforge.net/projects/aqemu/