user2707440
user2707440

Reputation: 41

Routing by linux iptables

I have 3 virtual machines called vm1 vm2 and vm3. I want to ping from vm1 to vm3 via vm2. vm1 has an interface eth0 having IP adress 192.168.221.10. Similarly, vm3 has eth0 having IP adress 192.168.221.11. vm2 has 2 interfaces which are eth1 (192.168.221.1 ) and eth2 (192.168.221.2). I want to control connections on vm2 and route them with the commands below

sudo iptables -t nat -A PREROUTING  -i eth2 -j DNAT --to 192.168.221.1        
sudo iptables -t nat -A PREROUTING  -i eth1 -j DNAT --to 192.168.221.11

However I cannot reach vm3 from vm1 in this way. Any idea of what is the problem. Thanks a lot.

Upvotes: 1

Views: 255

Answers (1)

Mandar Shinde
Mandar Shinde

Reputation: 1755

Make sure that you have enabled IP Forwarding on VM2 as your VM2 is acting as a router.

I've also posted an article on How to configure Ubuntu as a router using IPTables.

Upvotes: 1

Related Questions