There are literally dozen or more methods available on the internet for bridging qemu guest to the real network. But sadly, most of them are too complicated or too stupid to work. Below are simple steps for bridging a qemu guest to the host network.
- Release ip address on the host (dhcpcd -k eth0)
- Make sure eth0 is refreshed (ip link set eth0 down) (ip link set eth0 up)
- Create a bridge (brctl addbr bridge)
- Connect eth0 to bridge (brctl addif bridge eth0)
- Start ip-stack on bridge. (dhcpcd -n bridge)
Now, when qemu uses tap device, we should attach this device to bridge.
Add this line to /etc/qemu-ifup
brctl addif bridge $1
Here $1 is the name of the tap device that qemu uses for guest
When the guest is powered off, qemu should remove the interface of tap device from bridge.
Add this line to /etc/qemu-ifdown
brctl delif bridge $1
For connecting qemu guest to the bridge, just tell qemu to configure guest’s network using the tap device.
sudo qemu-system-i386 -enable-kvm -net tap,vlan=0,ifname=tap0 -net nic,vlan=0 -hda ~/Data/OS_DiskImages/ubuntu11.10/disk.qcow2
Here is a link to all the three scripts.