Network bridge
A network bridge is one of the possible ways to connect a QEMU Guest system to a real network. Bridging allows you to:
connect the QEMU guest to your LAN - the QEMU guest will appear on the LAN just like any other PC
use the real LAN in your QEMU guest - the guest can use the DHCP and DNS servers that are available to the other PCs on the LAN
of course, if your LAN has internet access, the QEMU guest can use this internet access as well
Bridging is one of the most powerful ways to connect a QEMU guest to a network, but it also has disadvantages:
it is a bit difficult to set up (some network experience is really helpful)
it affects the networking on the Host system, because it replaces the network interface on the host with a bridged interface
On FreeBSD it does work, it's easy to setup and it won't replace any network interface
Information about any other non-Linux hosts?
Linux
Setting up a bridge under Linux in general is described for example in the various Linux-bridging-Howtos, like
Before trying the below please understand your host's connectivity will be severed during the initial steps. Your kernel must support bridging. Most wireless interfaces will not allow you to bridge with them (see http://linux-net.osdl.org/index.php/Bridge for more information).
The basic steps to set up a bridge for linux host are like this:
Use bridge-utils to create the bridge:
brctl addbr br0 ifconfig eth0 0.0.0.0 promisc up brctl addif br0 eth0
Now configure br0 on the host as you would have done with eth0
ie: if you use dhcp on your lan - then dhclient br0.
Edit your qemu-ifup script (/etc/qemu-ifup):
#!/bin/sh sudo /sbin/ifconfig $1 0.0.0.0 promisc up sudo /usr/sbin/brctl addif br0 $1
Make sure your /etc/qemu-ifup script is executable. If not, add executable attribute to it: #chmod +x /etc/qemu-ifup
Specify that you want to use tun/tap when you start qemu. Also make sure your user has permissions to access /dev/net/tun:
sudo chmod 666 /dev/net/tun qemu ... -net nic,vlan=0 -net tap,vlan=0
You can now configure each guest as if it were on the host's lan - it essentially is.
Some suggestions and notes for bridging under linux:
Use your distributions configuration files to create and manage the bridge.
On debian based distros the bridge can be managed in /etc/network/interfaces:
auto br0 iface br0 inet static address 192.168.0.2 netmask 255.255.255.0 network 192.168.0.0 gateway 192.168.0.1 bridge_ports eth0 bridge_stp off bridge_maxwait 5 # referenced from http://qemu-forum.ipi.fi/viewtopic.php?t=374
Most wireless interfaces will not work - see the introductory paragraph.
Add another NIC to your host and bridge the tap interfaces with this.
Secure /dev/net/tun by adding both the node and your user to the same group.
Linux kernel 2.6.18+ is strict on the creation of tap devices - you can either run qemu as root (warning: qemu does NOT drop root perms) or use the method described in I'm using a kernel >=2.6.18 and am having problems with tun/tap and QEMU
FreeBSD
Setting up a bridge under FreeBSD is described in the FreeBSD Handbook: http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/network-bridging.html.
The basic steps to set up a bridge for FreeBSD hosts are:
Create a file in /etc/qemu-ifup with the following contents and make it executable:
#!/bin/sh
ifconfig ${1} 0.0.0.0
Run these commands with root permission (change the interface value according to your system):
/sbin/kldload bridge /sbin/sysctl net.link.ether.bridge_cfg=rl0,tap0 /sbin/sysctl net.link.ether.bridge.enable=1
If you have more than one virtual host, add the relative tap interfaces to the second line above and pay attention that the virtual hosts have ethernet cards with different MAC addresses.
Windows
The basic steps to set up a bridge for windows host can be found here:
http://www.h7.dion.ne.jp/~qemu-win/TapWin32-en.html The article doesn't specifically mention bridging, but you can bridge both the newly created tap adapter (provided by openvpn) and an ethernet interface from Network Connections. Then configure the bridge with the same settings the ethernet interface used. This seems to work, but I had a problem with the Tap interface remaining disconnected after you had started Qemu, even though this worked before the Tap interface was added to the bridge. If you open the properties of the Tap interface, click configure, click to Advanced Tab, and change the "Media Status" to "always connected", it then works!
NOTE: In some cases, if creating a bridge between a wireless adapter and the TAP adapter, it may be necessary to force the wireless network adapter to promiscuous mode. See this Microsoft Knowledge Base article: http://support.microsoft.com/kb/302348/en-us
See QEMU and network for further QEMU network related articles.
Back to FrontPage