Tony's ramblings on Open Source Software, Life and Photography

Using Bridged Networking For KVM / QEMU (and how to install)

There's so many different HOWTO's on the Internet regarding using bridged networking for kvm virtual machines. Unfortunately most are completely out of date, wrong or just don't apply to Ubuntu's implementation.

Believe it or not, it's not very hard. KVM/QEMU will automatically create the "tap" interface (actually it names them vnetX) and will even create a new MAC address for it. All we have to do is put our primary ethernet adapter into promiscuous mode and create a bridge device.

Both steps are easily done by editing /etc/network/interfaces. No additional scripts are needed if you're using static IP addresses.

Here's an example setup for preparing the host machine. This assumes you have one physical card in the machine (eth0) and that you want to access your host machine using 192.168.1.2:

# The loopback network interface
auto lo
iface lo inet loopback

# Create our bridge interface using a static IP address on the network
auto br0
iface br0 inet static
        address 192.168.1.2
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        pre-up ifconfig eth0 down
        pre-up ifconfig eth0 0.0.0.0 promisc up
        pre-up brctl addbr br0
        pre-up brctl addif br0 eth0
        bridge_fd 9
        bridge_hello 2
        bridge_maxage 12
        bridge_stp off

# Configure the actual Ethernet device in promiscuous mode and 
# add it to the bridge
iface eth0 inet manual
        pre-up ifconfig eth0 0.0.0.0 promisc up
        pre-up brctl addif br0 eth0
        pre-down brctl delif br0 eth0
        pre-down ifconfig eth0 down

Now, when setting up your virtual machine, tell it to use bridged networking over br0. That's all there is to it!

I have learned that in Ubuntu 8.04 the virt-manager can't seem to do an installation on a remote machine over SSH (locks up every time I try,) so I use the following command line to do an installation.

# This first line isn't needed in Ibex.  It also might be python-virtinst isntead of virt-install
sudo apt-get install virt-install
# Create the hard drive image
qemu-img create -f qcow2 myguesthd.qcow2 12G
# Create the virtual machine and attach to the virtual machine manager
virt-install --connect qemu:///system -n guestname -r 512 -f myguesthd.qcow2 -s 12 -c ubuntu-8.04.1-server-amd64.iso \
--vnc --noautoconsole --os-type linux --os-variant ubuntuHardy -v --accelerate --network=bridge:br0

Now I can connect to it remotely from my desktop using virt-manager and complete the installation.


Categories:

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <p>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for preventing automated spam submissions. It is case sensitive.
Image CAPTCHA
Enter the characters shown in the image.