Quick bridging with KVM on Ubuntu jaunty

It took me a little while to put the pieces together to figure out how to take a vm-builder created vm and use briding with it instead of kvm/qemu’s user-mode networking. All the pieces are available on the internet, but there was some emphasis lacking to make it all clear to me.

You’ll need to have a bridge set up on your host. Install the ‘bridge-utils’ package first. Then the relevant section of my /etc/network/interfaces file looks like:

# The primary network interface
auto eth0
iface eth0 inet manual
up ifconfig $IFACE up

auto br0
iface br0 inet static
bridge_ports eth0
bridge_stp off
bridge_maxwait 0
bridge_fd 0
bridge_hello 0

You could probably use ‘dhcp’ instead of a ‘static’ address on the bridge. The point is that your ipv4 address should be on the bridge, not on the actual interface.

Then create a ‘br-ifup’ script in your vm directory. This is based on /etc/qemu-ifup. This script is passed the name of the interface (tap0) which brings the interface up, and then adds it to your bridge.
#sudo -p "Password for $0:" /sbin/ifconfig $1
sudo /sbin/ifconfig $1 up
sudo /usr/sbin/brctl addif br0 $1

Then run kvm with something like this:

sudo kvm -m 128 -smp 1 -drive file=disk0.qcow2 -net nic -net tap,script=br-ifup

‘/etc/kvm-ifup: could not launch network script’ means that the script passed in ‘script=’ could not be found.

‘Could not initialize device ‘tap” means that kvm is unable to create the TAP/TUN interface. Running kvm as root via sudo is the easy solution.

‘warning: could not open /dev/net/tun: no virtual network emulation’ probably means that the ‘tun’ module isn’t loaded. You can load it with ‘sudo modprobe tun’.

The tap interface is removed from the bridge when the guest is shutdown.

5 thoughts on “Quick bridging with KVM on Ubuntu jaunty

  1. Marlon

    Thanks, I just reinstalled my Jaunty disk and found your instructions on setting up bridged networking within kvm. I had been using the qemu interface before but didn’t like it because of the limited configuration (e.g. no sdl). Thanks for posting this. I got it set up without a hitch!

  2. Cheif


    I’ve tried to make it work but it shows the message: “Could not initialize device ‘tap'” do you know wath could it be?
    I’ve been looking in google but I havent find anything…


  3. Rafo

    The “could not launch network script” may also indicate a problem with the script format. I was getting that diagnostic so I used `strace -f -e file kvm …’ and found out that there was a “ENOEXEC (Exec format error)” occurring behind the scene. This went away when I adjusted my script to strictly follow the convention for interpreter scripts in the EXECVE(2) manpage: The first line of the script should be


    where INTERPRETER is the absolute path of a binary executable (/bin/bash on my system).

  4. Pingback: Getting started with KVM on Ubuntu 9.04 « Solely For me

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.