Board index Linux Linux - Tips&Tricks

Moderator: chandranjoy

How to configure Red Hat Linux/CentOS as a router?

Postby chandranjoy » Wed Sep 01, 2010 8:09 pm

Limitation:
This is applicable for Red Hat Enterprise Linux/CentOS 3 and above.

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

To enable packet forwarding:

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



To make this permanent, set the variable net.ipv4.ip_forward = 1 in the /etc/sysctl.conf file. For example:


# Controls IP packet forwarding
net.ipv4.ip_forward = 1


Next, have iptables handle Network Address Translation:

/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE


where eth0 is "outside" or in public connection. Iptables ruleset should be tuned to be more restrictive. Do not forget to save iptables settings with:

service iptables save


See additional articles in the Knowledgebase for additional iptables configuration and tips.

To view the routing table use:

netstat -rn


To view iptables ruleset use:

iptables -L
chandranjoy
Site Admin
 
Posts: 283
Joined: Fri Oct 23, 2009 11:19 pm

Return to Linux - Tips&Tricks

Who is online

Users browsing this forum: No registered users and 1 guest


cron