Connecting qemu guest to real network using bridge

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.
  1. Release ip address on the host (dhcpcd -k eth0)
  2. Make sure eth0 is refreshed (ip link set eth0 down) (ip link set eth0 up)
  3. Create a bridge (brctl addbr bridge)
  4. Connect eth0 to bridge (brctl addif bridge eth0)
  5. 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.

  1. Starting bridge
  2. qemu-ifup script
  3. qemu-ifdown script
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s