How To: Make IP Forwarding Permanent in Linux

While IP forwarding in Linux is disabled by default, as most people don’t need it, there may be various reasons why you might want it enabled. Enabling IP forwarding is easy. First let’s check if it is already enabled, by running the sysctl command as follows:

$ sysctl net.ipv4.ip_forward

If it is disabled the result will be:

$ net.ipv4.ip_forward = 0

… otherwise instead of “0” the value will be “1”.

It gets this setting from the /proc/sys/net/ipv4/ip_forward file so another way of checking it is to just see what value is in that file, like this:

$ cat /proc/sys/net/ipv4/ip_forward

It will just return “0” for disabled or “1” for enabled. If it is disabled you can enable IP forwarding by changing the value from 0 to 1 using either of the following two commands with superuser privileges (sudo or login as root):

# sudo sysctl -w net.ipv4.ip_forward=1
# echo 1 > /proc/sys/net/ipv4/ip_forward

The latter may require you to be logged in as root. This would enable IP forwarding immediately, but after a reboot it will revert back to default. To permanently enable IP forwarding you would need to edit the /etc/sysctl.conf configuration file (with superuser privileges or as root). Specifically look for the lines that say:

# Uncomment the next line to enable packet forwarding for IPv4
# net.ipv4.ip_forward=1

To uncomment it just remove the hash sign # in front of net.ipv4.ip_forward=1, as the comment above it instructs. If the value there says “0” just change it to “1”. Once you save the file IP forwarding will remain enabled permanently, or until you disable it again.