IP Forwarding - Linux

OS: 
Function: 
Summary

On a Linux system, IP forwarding is enabled when the file /proc/sys/net/ipv4/ip_forward contains a 1 and disabled when it contains a 0. 

Detailed Description

The command echo writes the given argument, the string "1", to the standard output. Using the redirect operator (>) and a filename, the output of the command is written to a file. 

Disabling IP forwarding has an immediated effect but changes are not permanent and are lost when the system is rebooted. Modifying the IP fowarding state permanently requires changes to the configuration file /etc/sysctl.conf.

IP forwarding is enabled if the file contains a line net.ipv4.ip_forward = 1, and IP forwarding is disabled when the line doesn't exist or the file contais the line net.ipv4.ip_forward = 0. Changes to the configuration file /etc/sysctl.conf take effect the next time Linux is rebooted. 

Examples

Configuring a Linux PC as an IP router

Enable IP forwarding (enabled when file contains a 1):

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

Disable IP forwarding (disabled when file contains a 0):

PC1% echo "0" > /rpoc/sys/net/ipv4/ip_forward