Linux – iptables and virtual machines of KVM, external ip

iptableskvm-virtualizationlinuxroutessh

Hi everyone 🙂 In general, I'm still struggling with the virtual machine KVM. I did two alias to eth0 – eth0:0 and eth0:1 and put them on an external IPs (eth0:0 – 89.114.122.3, eth0:1 – 89.114.122.4)​​. Now the problem is: redirect from IP 89.114.122.3 and 89.114.122.4 IPs to virtual internal addresses (virbr0 bridge) of VMs obtained for dhcp …
I do like this:

sudo route add 89.114.122.3 gw 89.114.122.1 netmask 0.0.0.0 metric 1 dev eth0:0

/sbin/iptables -t nat -A PREROUTING -p tcp -d 89.114.122.4 -j DNAT --to-destination 192.168.122.86

sudo /sbin/iptables -A FORWARD -i eth0:0 -d 192.168.122.86 -j ACCEPT

but it still not work, neither ssh, nor other services… only ping on that external IP.

What I am doing wrong?

Best Answer

libvirt is already NATing, this is how you get the 192.168.122 address. Go over http://wiki.libvirt.org/page/Networking#NAT_forwarding_.28aka_.22virtual_networks.22.29 for some better understanding of what's going on.