Iptables – QEMU virtual networking NAT

iptablesqemuvirtualization

I'm trying to set up a virtual network as described here. These are my steps:

ifup eth0 # uses DHCP
brctl addbr br0
ifconfig br0 up 192.168.0.1
kvm ... -device e1000,netdev=tap0 -netdev type=tap,id=tap0,sccript=/etc/qemu-ifup

where qemu-ifup does

ifconfig tap0 0.0.0.0 promisc up
brctl addif br0 tap0

And finally, inside the vm,

ifconfig eth0 192.168.0.2
route add default gw 192.168.0.1

This allows me to ping 192.168.0.1 and 10.42.42.127 (the host's IPs) from inside the guest, and the guest from inside the host.

However, I cannot ping a guest from inside another guest, nor any other IP outside the host (10.42.42.1, or 8.8.8.8, for example).

How should I set this up?

Best Answer

There is two question:

1) Have you allowed a forwarding between br0 and eth0? You can check it via this command:

cat /proc/sys/net/ipv4/ip_forward

If you get a "0", you must correct it to "1":

echo "1" > /proc/sys/net/ipv4/ip_forward

You can allow it in the /etc/sysctl.conf permanently.

2) You have to have a NAT settings via iptables, for example somethink like:

iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE