Sunday, September 27, 2009

How to Configure Linux as a Router

It is not possible to purchase Network Router (like Cisco or Juniper) for communication between two different networks on a LAN, although we need router for that in any case, as Router is the device which is used for communication between two different networks. So we should go for economic solution so that it charge us less and also results in proper output.

This can be done by using Linux Machine as a Router, we have some simple steps to do it, using Network Address Translation (NAT).

1. Enable packet forwarding . Make it permanent by adding "net.ipv4.ip_forward = 1" to /etc/sysctl.conf

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

2. Enable iptables to handle NAT. ( eth0 is the public Interface )

/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

3. Save iptables settings

# service iptables save

4. Done. Check by routing table by verifying "netstat -nr" and iptables rules by "iptables -L"


This is the simplest method and for iptables consult the one and only "GOOGLE".

I hope it will be informative for you :)

No comments: