Qemu Networking (Tun/Tap)

Hi friends,

Setting up networking in Qemu instance is very simple if you are using ‘user mode’ networking stack. And most of us don’t care about Full fledged networking while using Qemu Guests. But configuring Network in Qemu with full access requires TUN/TAP configuration.

Here is some simple steps which I did to configure TUN/TAP in Ubuntu 9.04,

Inside Ubuntu(Host), type the following commands:

$ sudo apt-get install qemu kqemu-common kqemu-source
$ wget ftp://ftp.osuosl.org/pub/lfs-livecd/lfslivecd-x86-6.3-r2145-min.iso
$ sudo qemu -cdrom lfslivecd-x86-6.3-r2145-min.iso -boot d -kernel-kqemu -m 512 -net nic -net tap &
$ sudo ifconfig tap0
$ sudo sysctl -w net.ipv4.ip_forward=1
$ sudo iptables -t nat -A POSTROUTING -j MASQUERADE
$ sudo iptables -t filter -P FORWARD ACCEPT

Inside lfslivecd(Guest) type the following commands:

$ ifconfig eth0
$ route add default gw
$ cat > /etc/resolv.conf <<EOF

Ofcourse, you can use any distro as a guest in qemu. Enjoy Qemuing.

2 thoughts on “Qemu Networking (Tun/Tap)

  1. hello mohan,
    can you please make it more clearer.
    i tried as per these steps but not succeeded.
    i am working on a laptop with ethernet ip and for tap0 i assigned
    my computer is connected to router using wired lan.
    then i assigned to the guest OS then it is supposed to ping to the host system but it is not doing.
    if you find some time then please reply.

    • I think your ‘eth0’ and ‘tap0’ subnets are same (, But in my post, I assigned different subnet to ‘tap0’ (, We should assign ip from this same subnet ( to LFSLiveCD’s ‘eth0’ interface.

      Assign ( to ‘tap0’ and assign ( to LFSLiveCD’s ‘eth0’. I hope this will clear your problem.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s