I often need to quickly setup a router using my linux laptop and hence documenting the general steps.
Lets assume wlan0
is the internet facing interface while eth0
is the LAN interface.
Add/Edit the following in /etc/sysctl.conf
net.ipv4.ip_forward = 1 net.ipv6.conf.all.forwarding = 1
Execute the following command to setup the sysctl values.
sudo sysctl -p /etc/sysctl.conf
Make sure the default route is pointing to wlan0
Masquerade on the internet facing interface i.e. wlan0
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
Now give eth0
an IP and use an IP in the same broadcast range as eth0
for the device sitting on the LAN.
For eg
sudo ifconfig eth0 192.168.137.1
And now use 192.168.137.2
for the device on the LAN network.
Additional step could be to setup a dhcpd server on the eth0 interface. Here’s a sample dhcpd configuration
default-lease-time 600; max-lease-time 7200; subnet 192.168.137.0 netmask 255.255.255.0 { range 192.168.137.2 192.168.137.254; }
Now to run the dhcpd server on eth0
sudo dhcpd -f -cf /etc/dhcpd.conf eth0
Remove the -f
if you want to run dhcpd in background.