TAP that DHCP bridge for some Qemu TUN in Fedora
by plouj on Jul.29, 2008, under HOWTO
The other day I needed to setup bridged networking for a Qemu virtual machine. Although I found a rather well written generic TAP interfaces guide on Wikibooks. It only explained how to configure a network bridge on a host machine with a static IP. I wanted to do this on a host that used DHCP. Plus I wanted to keep all configuration in Fedora specific places. Having discovered a good way to do this through experimentation after a few fruitless Google searches I thought it would be useful for myself and others to have the configuration documented here.
ifcfg-eth0
First, I changed the host’s (auto-generated) /etc/sysconfig/network-scripts/ifcfg-eth0 script from this:
# Attansic Technology Corp. L1 Gigabit Ethernet Adapter DEVICE=eth0 BOOTPROTO=dhcp HWADDR=00:1D:60:35:A7:64 ONBOOT=yes
to this:
# Attansic Technology Corp. L1 Gigabit Ethernet Adapter DEVICE=eth0 TYPE=Ethernet BRIDGE=br0 ONBOOT=yes
This turns off DHCP on the physical Ethernet device and just specifies that it will be connected to or a part of a bridge.
ifcfg-br0
Second, I created /etc/sysconfig/network-scripts/ifcfg-br0, which will be called to setup a bridge device:
DEVICE=br0 TYPE=Bridge BOOTPROTO=dhcp HWADDR=00:1D:60:35:A7:64 ONBOOT=yes DELAY=0 STP=off
As you can see, most of this configuration is copied from eth0 plus the bridge configuration as per the Qemu Wikibook.
qemu-ifup/down
Third, I shortened the /etc/qemu-ifup and /etc/qemu-ifdown from Wikibooks to get this:
/etc/qemu-ifup:
#!/bin/sh USER=$(id -un) sudo /usr/sbin/openvpn --mktun --dev $1 --user "$USER" sudo /sbin/ifconfig $1 0.0.0.0 promisc up sudo /usr/sbin/brctl addif br0 $1
/etc/qemu-ifdown:
#!/bin/sh sudo /sbin/ifconfig $1 down sudo /usr/sbin/brctl delif br0 $1 sudo /usr/sbin/openvpn --rmtun --dev $1
Here I basically removed all of the configuration that is taken care of in the sysconfig scripts. I also made explicit use of sudo simply because that is my preference.
Final steps
Now I can simply run /etc/qemu-ifup tap0 once to create a TAP device, and use something like: qemu-kvm -hda /virtual-machines/fedora9.disk -m 512 -net nic -net tap,ifname=tap0,script=no to start a virtual machine. When I’m done running the virtual machine, I can run /etc/qemu-ifdown tap0 to remove the TAP device.
All this sounds simple now that it’s working, but initially it took a lot of guessing on my part so I’m documenting it here for the future.
I would appreciate it if someone can point me to the official Redhat/Fedora documentation on editing /etc/sysconfig/network-scripts/ scripts.

December 2nd, 2008 on 8:32 pm
Hi,
Do you happen to have any updates on this? I installed FC10 and the TYPE=Bridge does not seem to do anything the “network” script (it is not a reconized type.
Thanks
A
December 2nd, 2008 on 9:37 pm
No. Sorry. It’s going to be a while before I upgrade to, much less try this in Fedora 10. Your best bet would be digging through the actual /etc/init.d/network script and the files that it sources.
January 15th, 2009 on 5:19 pm
Hi A,
I have this setup on Fedora 10. Works for me.
October 5th, 2009 on 3:17 pm
I tried to follow your method, but it seems that I might need some additional configurations. Do I have to do some configurations inside guest, or with DNS server, as my guest doesn’t get an IP address? Do I need any additional configuration like
sudo sh -c “echo ’1′ > /proc/sys/net/ipv4/ip_forward”
or to enable NAT like:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Please any help!!
P.S. I’m running Fedora 8
October 12th, 2009 on 10:54 pm
I got this slightly simpler set-up to work (in Fedora 11):
/etc/qemu-ifup contains “ifup $1″
and
/etc/sysconfig/network-scripts/ifcfg-tap0 contains:
DEVICE=tap0
TYPE=Tap
BRIDGE=br0
(you need to install the package “tunctl” for this work)