Account Links: Cart | Your Account | Logout

Skip to content

Red Hat Knowledgebase

Red Hat Knowledgebase Search:

Updated Within the Last:

New Solutions within the last day New Solutions within the last week New Solutions within the last month

Browse by topics:


Click to View a Topic
Red Hat Enterprise Linux > Networking > Issue <<  23 of 354 >>

Solution Tools:


Email a Solution Postcard Printer version Submit a comment on this answer Update notifications Request an answer Back

Article Reference

Article ID: 487
Last update: 06-16-06
Issue:
What are the basics to configure Red Hat Enterprise Linux as a router to perform Network Address Translation (NAT) using iptables?
Resolution:

Limitation:
This is applicable for Red Hat Enterprise Linux 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


How well did this entry answer your question?


good wrong incomplete out of date
Red Hat Enterprise Linux > Networking > Issue <<   23  of  354  >>