Tuesday, March 03, 2009

Configuring LAN with BSNL Datone in Linux machine

This is how I configured my home LAN with one desktop and one laptop. Before listing the exact steps let me brief the background. The desktop runs on CentOS and acts as the gateway for the LAN machines. Main difficulty was implementing the NAT so that I could access Internet from my Laptop. Looking at the tldp documentation, I thought it would be fairly easy to implement ip masquerading using iptables. Actually it was but only after I found the correct fix when Internet is provided through PPPoE protocol. The point to remember with PPPoE is the outgoing port in these situation will be ppp* not eth*.


+-------------+ +-------------+ +-------------+
----| | | | 10.0.0.* | |
BSNL| Modem | 192.168.1.* | Gateway |---------------| Internal M/C|
Cable| |---------------| (CentOS) |eth1 | (Ubuntu) |
| | (ppp) eth0| | | |
+-------------+ +-------------+ +-------------+




Step 1:
[root ]# echo 1 >  /proc/sys/net/ipv4/ip_forward

Step 2:
[root ]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf

Step 3:
[root ]# echo 1 >  /proc/sys/net/ipv4/ip_dynaddr

Step 4:
[root ]# /sbin/iptables -A FORWARD -i eth1 -o ppp0 -m state --state RELATED,ESTABLISHED -j ACCEPT

Step 5:

[root ]# /sbin/iptables -A FORWARD -i ppp0 -o eth1 -j ACCEPT

Step 6:
[root ]# /sbin/iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

Step 7:
[root ]# service iptables save

Step 8:
[root ]# service iptables restart

Step 9:
If you have some firewalls (like Redhat Firewall) enabled in your system, you must make the LAN interface trusted in the gateway machine.

And there you go. Step 4-9 can also be done using UI: /usr/bin/system-config-securitylevel-tui like this:



P.S.: Chennai LUG helped me for this.

No comments: