How to set a two-way networking with qemu/kvm

Here is an example for debian and kvm.

On a host machine:

sudo kvm -net tap,script=/etc/kvm/kvm-ifup -net nic -m 256 -hda debian-lenny.img -curses
ifconfig tap0

In a virtual machine:

echo 'iface eth0 inet static
        gateway' >> /etc/network/interfaces

Can I haz internets on my guest now?

On a host system:

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

In a guest system:

echo 'nameserver' > /etc/resolv.conf