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 192.168.10.1
$ 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 192.168.10.2
$ route add default gw 192.168.10.1
$ cat > /etc/resolv.conf <<EOF
nameserver 208.67.222.222
nameserver 208.67.220.220
EOF
$

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

Advertisements

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 192.168.1.101 and for tap0 i assigned 192.168.1.102.
    my computer is connected to router using wired lan.
    then i assigned 192.168.1.110 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.
    Thanks

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

      Assign (192.168.10.1) to ‘tap0’ and assign (192.168.10.2) 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 )

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