Awasu » Banana Pi gateway: Setting up NAT
Tuesday 1st March 2016 9:22 PM []

Network Address Translation allows the gateway to send requests out to the internet on behalf of computers on the internal network. When the gateway receives an internet request, it tweaks it slightly to make it look like it was sending the request itself, and then forwards it on to the intended recipient on the internet. When the reply comes back, they gateway tweaks it again to make it look like nothing happened i.e. the computer on the internal network thinks it was communicating directly with the remote computer on the internet.

To set this up, we first need to enable IP forwarding in the kernel. Edit /etc/sysctl.conf and uncomment the net.ipv4.ip_forward=1 line.

To reload these settings:

sudo sysctl -p /etc/sysctl.conf

We also need to enable IP masquerading:

sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

This command tells the gateway to forward any internet requests to the wlan0 interface i.e. my wifi connection, which is how I connect to the internet.

Since we need this to always happen, the above command should be added to /etc/rc.local.

« Setting up DNS

Tutorial index

Setting up a WiFi access point »

Have your say