Pre-requisites

  $ sudo apt-get install bridge-utils
  $ grep CONFIG_TUN /boot/config-`uname -r`

Setup

/--------\   /----\   /----\   /----\   /--------\
|Internet|---|eth0|---|br0 |---|tap0|---|Guest NIC
\--------/   \----/   \----/   \----/   \--------/

br0 is host NIC. Guest OS interface will write to tap0. Bridge interface exists between eth0 and tap0.

Configure /etc/network/interfaces

auto tap0
iface tap0 inet static
        pre-up tunctl -u shaks -t tap0
        address 172.20.0.1
        netmask 255.255.255.0

auto br0
 iface br0 inet static
        address 192.168.1.211
        network 192.168.1.0
        netmask 255.255.255.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        bridge_ports eth1
        bridge_fd 9
        bridge_hello 2
        bridge_maxage 12
        bridge_stp off

Replace shaks with your username.

Restart network services

  $ sudo /etc/init.d/networking restart

Output of /sbin/ifconfig -a:

br0       Link encap:Ethernet  HWaddr 00:19:d1:2e:06:33
          inet addr:192.168.1.211  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::219:d1ff:fe2e:633/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:27082 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14138 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:39812909 (37.9 MiB)  TX bytes:967808 (945.1 KiB)

eth1      Link encap:Ethernet  HWaddr 00:19:d1:2e:06:33
          inet6 addr: fe80::219:d1ff:fe2e:633/64 Scope:Link
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
          RX packets:30099 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14436 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:40510727 (38.6 MiB)  TX bytes:1009758 (986.0 KiB)

lo        Link encap:Local Loopback
          LOOPBACK  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

sit0      Link encap:IPv6-in-IPv4
          NOARP  MTU:1480  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

tap0      Link encap:Ethernet  HWaddr 7e:41:cc:74:e4:95
          inet addr:172.20.0.1  Bcast:172.20.0.255  Mask:255.255.255.0
          inet6 addr: fe80::7c41:ccff:fe74:e495/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:156 overruns:0 carrier:0
          collisions:0 txqueuelen:500
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Output of /sbin/route -n:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 br0
172.20.0.0      0.0.0.0         255.255.255.0   U     0      0        0 tap0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 br0

Output of brctl show:

bridge name     bridge id               STP enabled     interfaces
br0             8000.0019d12e0633       no              eth1

Add tap0 interface to the bridge, using:

  sudo brctl addif br0 tap0

Verify the same with brctl show:

bridge name     bridge id               STP enabled     interfaces
br0             8000.0019d12e0633       no              eth1
                                                        tap0

Test

Ping gateway, Internet:

  ping -c3 192.168.1.1
  ping -c3 www.google.com

Bibliography

  1. [QemuNetwork]. QEMU and network. http://calamari.reverse-dns.net:980/cgi-bin/moin.cgi/QemuNetwork.

  2. [QemuAndTuntap]. QEMU and Tuntap. http://calamari.reverse-dns.net:980/cgi-bin/moin.cgi/QemuAndTuntap.