0

I have 3 virtual machines installed on vmplayer. Out of which I have made two of them as host of two different network. Host1 ip=192.168.1.13 gateway=192.168.1.11 and Host2 ip=192.168.2.14 and gateway=192.168.2.12 . Now I want the third virtual machine as router which can transfer packets from first virtual machine to second virtual machine has two adapters eth0 ip=192.168.1.11 and eth1 ip=192.168.2.12 . Host1 is connected to eth0 and Host2 is connected to eth1. How shall I configure the router so that the two hosts can communicate and NAT'ing could be performed? Please do reply as soon as possible.

Itai Ganot
  • 10,424
  • 27
  • 88
  • 143
Krati Jain
  • 13
  • 1
  • 2

1 Answers1

1

You don't say what OS so you have to deal with assumptions - so assuming Debian derivative

Enable forwarding. In /etc/sysctl.conf set: net.ipv4.ip_forward=1

That is all you need to get to ping A -> B.

Because you also want NAT for some reason, in /etc/rc.local - add modules you need - eg:

modprobe ipt_conntrack
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ip_conntrack_irc
modprobe ip_nat_irc
modprobe ip_nat_snmp_basic

Also in /etc/rc.local add:

iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 192.168.1.11
iptables -t nat -A POSTROUTING -o eth1 -j SNAT --to-source 192.168.2.12

If you wanted the gateway to also access the internet for example, then you would give it a third interface, eg, eth2 with an IP address on your LAN, eg 10.0.0.200 then add this:

iptables -t nat -A POSTROUTING -o eth2 -j SNAT --to-source 10.0.0.200

or if it had a DHCP address (ie, its not a static address) then do this instead

iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE

then lastly make sure that the gateway has a default route pointing to your Internet LAN gateway, fiber line or DSL modem. This would be done automatically anyway if it's DHCP assigned.

Ian Macintosh
  • 945
  • 1
  • 6
  • 12
  • Sorry, but the ping is still not working.Do I have to keep the router configured virtual machine adaptors set as NAT? – Krati Jain Jul 17 '14 at 16:36
  • You do need to restart networking after enabling ip_forward. Did you do that? – Ian Macintosh Jul 17 '14 at 20:18
  • I just made 3 VM's and tested the above. Works perfectly in both cases - ie, without NAT and with NAT (Heading out for a long weekend's leave so I'll check back Tuesday see how you got on). – Ian Macintosh Jul 17 '14 at 21:04
  • Thank you. It worked fine. Now, I am getting problem with making same router machine as bridge and perform bridging. Can you help? :) – Krati Jain Jul 23 '14 at 11:35
  • Make a new question with details Krati and I'll try to have a look. Also mark this as the answer so the other Googlers see it easier :-) – Ian Macintosh Jul 23 '14 at 14:04