tun/tap networking for VMs on linux using iproute2

So the guides for tun/tap are all different, and they seem to all include bridges, which are eeky, i don't even understand how bridges work.

This method will let your guest have a separate ip routed through the host.

Bridges are nice if you want dhcp, but they hinder what you can do with your network, so this is a guide on how to set up your networking for simple routed networking with a guest os and a host, using tun/tap interfaces.

host os

This works at least on lguest, qemu and xen with small variations, so here is the qemu example: These commands should mostly be issued as root, but you could start a qemu vm as a user, set up networking as root, should work fine

    TAP=$(sudo tunctl -b -u $youruser)
   or as root
    TAP=$(sudo tunctl -b)
    ip link set $TAP up arp on
    ip addr replace dev $TAP $your.host's.ip.addr
    ip route add $guestIP via $your.host's.ip.addr dev $TAP
    echo 1 > /proc/sys/net/ipv4/conf/$TAP/proxy_arp
    echo 1 > /proc/sys/net/ipv4/ip_forward
    echo 1 > /proc/sys/net/ipv4/conf/$MAIN_IFACE/proxy_arp

where $MAIN_IFACE is the interface of the host that is connected to the external network.

I have chose this type of networking because it doesn't add yet an other layer of indirection in hte network stack. You can't use bonded interfaces on bridges, etc.

Guest os

This largely depends on your guest os of course, the main things are: