NAT routing between two interfaces

There are two subnets: 192.168.0.* and 192.168.10.*. COMPUTER_2 is connected to the ROUTER and has access to Internet. COMPUTER_1 sits on another subnet and does not see Internet. What we want is to make COMPUTER_2 do the Network Address Translation (NAT) a.k.a. IP masquerading for COMPUTER_1, so that COMPUTER_1 is able to connect to Internet.

+------------------+        +--------------------------------+        +--------------------+
|    COMPUTER_1    |        |          COMPUTER_2            |        |       ROUTER       |
+------------------+        +--------------------------------+        +--------------------+
|                  |        |                                |        |                    |
|  192.168.10.101  |------->|  192.168.10.102 / 192.168.0.2  |------->|  192.168.0.1 / ... |-------->Internet
|                  |        |                                |        |                    |
+------------------+        +--------------------------------+        +--------------------+

The COMPUTER_2 has the following network interfaces:
eth0      192.168.0.2
wlan2     192.168.10.102

At COMPUTER_2 do:

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

At COMPUTER_1 do:

 route add default gw 192.168.10.102
 echo 'nameserver 8.8.8.8' > /etc/resolv.conf

P.S.
Settings will be reset back to what they were after reboot

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s