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)? I was surprised how easy it is to set up your Linux host as a NAT, it is just a few command lines.
OK, here is the setup on Host: - 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
Setup on 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