Monday, April 20, 2009

Configure Linux/Fedora as a Router | Enable Packet Forwarding in Linux/Fedora

Configuring a Linux Box as a Router is a easy task.

Step1: Set net.ipv4.ip_forward = 1 in the file /etc/sysctl.conf

Step2: Restart Network Service, command: service network restart
Note: If you do not want to Restart Network Service, use the following command to enable
packet forwarding: echo "1" > /proc/sys/net/ipv4/ip_forward

Step3: Add the static routes to different subnets, hosts etc. using the command: route add .....

Note: This will work if, the firewall don't block the packets from one sub-net to another.

Enable NAT on Linux|Configure NAT on Linux

NAT enabling is suitable when a Linux Box works as a router.

Assuming that, the Linux box has two network interface with the following parameters.

eth0: IP Address, connected with Local LAN.
eth1: IP Address, connected with WAN, Gateway:

To enable NAT for the Local Private LAN, iptables can be used.
Command is: iptables -A POSTRUTING -t nat -s -o eth1 -j MASQUERADE
Note: This will work if,
1) the Linux Box is already configured to work as router.
2) the firewall don't block the packets from Private LAN to WAN.