NAT with Linux
To share an internet connection may sometimes be very practical when working with embedded devices. The network may have restrictions/authentications that stops you from plug in your device into the network of the big company you are working for.
But what about creating your own network and use your computer as NAT (Network Address Translation)?
It is not that hard to setup, it is actually just a few command lines away.
eth0 has ip address 192.168.1.50 and is connected to the company network
eth1 has ip address 10.2.234.1 ans is connected to the target
eth0 has ip address 10.2.234.100 ans is connected to host
First of all, we need to setup a default gateway on our target, do this as you allways do - with route.:
Target$ route add default gw 10.2.234.1 eth0
Next, we need to create a post-routing rule in the to the NAT table that masquerades all traffic to the eth0 interface. iptables is your friend:
Host$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Thats it! Well, allmost. We just need to enable ip-forwarding.:
Host$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward