On Mon, Feb 09, 2009 at 08:22:02PM -0700, David G. Miller wrote:
I've been playing around with qemu and wanted to make the guest OS instance visible on my network. This meant getting bridging and tun/tap working. After getting things working by pasting command from the
[snippage]
I do it differently for my UML instances, but I don't see why this shouldn't work with qemu as well.
Firstly I have a simple boot script that creates the bridge and binds the real interface (eth1 in my case) to the bridge.
#!/bin/sh
# BRIDGE Create br0 with just eth1 bound # # chkconfig: 2345 09 91 # description: Activates br0
case "$1" in start) touch /var/lock/subsys/BRIDGE
/sbin/ifconfig eth1 0.0.0.0 promisc up
/usr/sbin/brctl addbr br0 /usr/sbin/brctl stp br0 off /usr/sbin/brctl setfd br0 1 /usr/sbin/brctl sethello br0 1 /usr/sbin/brctl addif br0 eth1 ;; stop) # Do nothing rm -f /var/lock/subsys/BRIDGE ;; status) echo $"Configured devices:" /usr/sbin/brctl show ;; restart|reload) # No nothing ;; *) echo $"Usage: $0 {start|stop|restart|reload|status}" exit 1 esac
exit 0
Then in my /etc/sysconfig/network-scripts area, I have br0 with the IP address I want. In my case, it's static
% cat /etc/sysconfig/network-scripts/ifcfg-br0 DEVICE=br0 ONBOOT=yes BOOTPROTO=static BROADCAST=10.0.0.255 IPADDR=10.0.0.136 NETMASK=255.255.255.0 NETWORK=10.0.0.0 TYPE=Ethernet
So what this means is that at bootup time the system will come up with br0 connected to the network and everything runs as normal. Basically, at this stage you can treat your machine as if 'br0' is the network device.
Now adding a new tap device to the bridge would be as simple as int=`tunctl -b -t $TAPNAME` ifconfig $int 0.0.0.0 promisc up brctl addif br0 $int
Now the new tap device is connected to the external network and the other side of the tap (the guest) can get an external IP address (eg via dhcp, or static) as normal.
On the host, only br0 shows as an IP address. The physical device (eth1) and added taps don't have an address when viewed with "ifconfig".