Friday, April 16, 2010

Linux Router How to

How to setup Linux as a router [ Throttler Machine ]

There are a few ways to set up a Linux machine as route. Here is a relatively straight forward and common method. This method requires that the system use iptables for Network Address Translation (NAT).

This step by step small how to will help you to setup Linux router only in 2 minutes.

Configuration steps

  • First enable packet forwarding
  • Next setup Network Address Translation using IPTABLES MASQUERADE targets
  • Save the changes
  • Verify everything is working

A) We are using OEL Linux distro

B) eth0 is internet interface (connected to router for example) and eth1 connected to our internal LAN (connected to your HUB/Switch for example).

My Linux eth1 --> Intranet [ 192.168.0.1 ]

box eth2 --> Lan [ADC] [ 10.23.X.X ]

Step I : Turn on ip forwarding in kernel

I) Open linux kernel configuration file (you must be a root user or use su - command to become a root user):

# vi /etc/sysctl.conf

II) Add/modify following line:


net.ipv4.ip_forward = 1

Step II: Restart network


# /etc/init.d/network restart

Step III: Setup IP forwarding and Masquerading (to act as router), you need to use NAT option of iptables as follows (add following rules to your iptables shell script if you want to make it permanent that is /etc/init.d/iptables in the start section :

# iptables --table nat --append POSTROUTING --out-interface eth2 -j MASQUERADE
# iptables --append FORWARD --in-interface eth1 -j ACCEPT

Step IV: You are done! Test it with ping

No comments:

Post a Comment