blog hits

Web Counters

Saturday, July 18, 2009

share the internet connection in linux

i had the same problem when i started to explore the internet to find the solution to share the internet in my computer. I use Fedora 11. But the below mentioned method is a common way of sharing internet in any linux distributions.

first of all lets look at the topology of network we are going deal with.


{internet}-----(XXX0 / 10.0.0.1)-> PC-A -(YYY0/192.168.0.1)-----------(ZZZ0/192.168.0.2)-> PC-B

We need to share the internet connection to PC-B from PC-A. PC-A is directly connected to the internet via an network interface (such as eth0 or wlan0 or ppp0). We take that interface as XXX0. But please make sure to change the XXX0 to the appropriate network interface which u are connected to the internet.

same as that PC-B is connected to PC-A via interfaces YYY0, ZZZ0 respectively. Once again please make sure you substitute the interface names with the appropriate interface names of yours. (you can check the interface names by ifconfig command)

The architecture of sharing the internet is not hidden in the linux as microsoft does in thier OS. So we should enable the NAT in the internet connected PC, which works as a NAT router. and we should also enable the remote packet forwarding too. This is by default disabled. Now lets work it out...

1) Change to root (this is a must)

su - root

2) Enable IP forwarding

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

edit /etc/sysctl.conf

and set.....

# Controls IP packet forwarding

net.ipv4.ip_forward = 1

3) Configure NAT functionality

- remove excisting IPTABLE entries

iptables -F
iptables -t nat -F
iptables -t mangle -F

iptables -X
iptables -t nat -X
iptables -t mangle -X

- Now save the iptables rules

service iptables save
service iptables restart

- Set the nat assuming the internet interface is XXX0

iptables -t nat -A POSTROUTING -o XXX0 -j MASQUERADE
service iptables save
service iptables restart


4) Restart network

service network restart

here we go click the PC-Bs web browser and surf the internet.. Enjoy.

Linux is beautiful. And it gives us the real feeling of working on it. Coz we configure it for our own style. This tutorial is for novice users. For next level of linux users they can utilize the above setting according to their needs.

0 comments:

Post a Comment