April 25, 2009

Redhat Linux Internet Connection Sharing !!!!

Q. How do I configure Redhat Linux computer to share my internet connection? How do I configure RHEL as a software router with two interfaces? How do I share my single connection with other PCs on LAN?

A. Linux can be easily configured to share an internet connection using iptables. All you need is two network interface cards as follows:
a) Your internal (LAN) network connected via eth0 with static ip address 192.168.1.254
b) Your external WAN) network is connected via eth1 with static ip address 192.168.2.1

Please note that interface eth1 may have public IP address or IP assigned by ISP.

Step # 1: Enable Packet Forwarding

Login as the root user. Open /etc/sysctl.conf file
# vi /etc/sysctl.conf


Add the following line to enable packet forwarding for IPv4:
net.ipv4.conf.default.forwarding=1


Save and close the file.

Restart networking:
# service network restart

Step # 2: Enable IP masquerading

In Linux networking, Network Address Translation (NAT) or Network Masquerading (IP Masquerading) is a technique of transceiving network traffic through a router that involves re-writing the source and/or destination IP addresses and usually also the TCP/UDP port numbers of IP packets as they pass through. In short, IP masquerading is used to share the internet connection.

Share internet connection

To share network connection via eth1, enter the following rule at command prompt (following useful for ppp0 or dial up connection):


# service iptables stop
# iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
# service iptables save
# service iptables restart

Open your Windows / Linux computer networking GUI tool and point router IP to 192.168.1.254 (eth0 Linux IP). You also need to setup DNS IP such as 10.0.0.21 and 10.0.0.22 . You should now able to ping or browse the internet:
c:> ping 202.54.1.20
c:> ping google.com

1 comment:

  1. Awesome stuff!!!!!!!!!!!

    Keep it up bro.........

    Regards,

    Ajay Singh Guleria

    ReplyDelete