When a computer forwards a packet that it has received from the network on to a remote system, it is called IP forwarding. All Linux systems can be configured to forward IP packets. In general, hosts do not forward datagrams, but routers must.
To use a Linux system as a router, enable IP forwarding by setting the correct value in the /proc/ sys/net/ipv4/ip_forward file. If the file contains a 0, forwarding is disabled. If it contains a 1, forwarding is enabled. A cat of the ip_forward file shows the current setting for your system:
$ cat /proc/sys/net/ipv4/ip_forward
Write a 1 to the file to enable forwarding:
[root]# echo "1" > /proc/sys/net/ipv4/ip_forward [root]# cat /proc/sys/net/ipv4/ip_forward
If you intend to run your Linux system as a router, stow this command in the rc.local file to enable forwarding every time the system boots.
On Red Hat Linux 7.2, you can edit /etc/sysctl.conf and change net.ipv4.ip_forward = 0 to net.ipv4.ip_forward = 1. Other distributions may use different configuration files for the same purpose. Writing a value directly to /proc/sys/net/ipv4/ip_forward should work on all current distributions.
Regardless of whether the system is a router or a host, it can make final delivery only if it is on the same network as the destination host. In all other cases, the system must send the packet on to a router. The routing table tells the local system which router the packet should be sent to.
Was this article helpful?