Linux as Router/Gateway

Yes, its possible to configure your Linux machine  as a router that manages different networks and routing packets, or as a gateway to the internet. All can be done by Linux firewall's (iptables) packet forwarding feature. Eg:If your linux box has two NICs, one connected to Internet and another connected to local LAN. Linux can forward all requests from lan to  to internet. So all PCs in the LAN can access the internet by setting linux box's ipaddress as default gatway.

Please go through the below network diagram


Here Linux PC has four NIC cards and all four are diffrent networks.  Linux Box can act as a router that manages 4 different networks. 
Step1:First of all make sure you have firewall enabled.
[root@server ~#]service iptables status
[root@server ~#]service iptables start
[root@server ~#]chkconfig iptables on

Step2: Go to GUI mode and  select System->Administration->Firewall
then select "Masquerading" and tick the WAN interface,here "eth3" (internet connected).
and save the firewall changes.(masquerading also can be done in command line interface)

Step3:restart iptables
[root@server ~#]service iptables restart

Step4: In all client machines  set local ipaddress of Linux machine of the same network as "default router"
(Here in the pc with ipaddress 192.168.10.50, set 192.168.10.1 as default gateway ) also set DNS addresses of the ISP in all client computers as Prefered DNS and alternative DNS(or use google's public DNS servers 8.8.8.8 and 8.8.4.4.)
Do this in all PCs.
Now ping google.com from client PCs or/and browse internet in web browsers.


You can also masquerade other interfaces inthe same way, and make your perfect router.


0 comments:

Related Posts Plugin for WordPress, Blogger...

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Coupons