Posts Tagged ‘linux’

Linux machine can be setup as gateway to allow the machines which are present in local network to communicate with external machines/internet.

Linux machine should have atleast two network interfaces, say eth0 – connected to internet, eth1 – connected to local LAN.

1. Enable IP forwarding

echo 1 > /proc/sys/net/ipv4/ip_forward

2. Run the following commands ( assuming 192.168.187.0/24 as the subnet of LAN. )

iptables –table nat –append POSTROUTING –out-interface eth0 -j MASQUERADE
iptables –append FORWARD –in-interface eth1 -j ACCEPT
iptables -I FORWARD 1 -s 192.168.187.0/24 -j ACCEPT
iptables -I FORWARD 1 -d 192.168.187.0/24 -j ACCEPT

You are done….

I am using static IP addresses here. If you need to use DHCP, you have to setup DHCP server also.