How to enable IP forwarding in Linux

Last updated on March 22, 2012 by Dan Nanni

To check whether IP forwarding is enabled or not, you can run the following command. The output 1 means that IP forwarding is enabled, and 0 means that IP forwarding is disabled.

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

If you want to enable IP forwarding on the fly, you can use sysctl command as follows. IP forwarding will be activated immediately without rebooting.

For IPv4:

$ sudo sysctl -w net.ipv4.ip_forward=1

For IPv6:

$ sudo sysctl -w net.ipv6.conf.all.forwarding=1

Note that IP forwarding enabled by sysctl command does not remain active across reboots, which means that IP forwarding becomes disabled after rebooting.

If you want to enable IP forwarding permanently, edit /etc/sysctl.conf as follows.

$ sudo vi /etc/sysctl.conf
net.ipv4.ip_forward=1           # For IPv4
net.ipv6.conf.all.forwarding=1  # For IPv6

Then reload sysctl.conf.

$ sudo sysctl -p /etc/sysctl.conf

Finally, restart networking to activate the change:

On CentOS, RHEL or Fedora:

$ sudo service network restart

On Debian or Ubuntu:

$ sudo /etc/init.d/networking restart

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean