How to enable IP forwarding in Linux

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 it's not.

$ 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.

$ sudo sysctl -w net.ipv4.ip_forward=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

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

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

Leave a comment

Your email address will not be published. Required fields are marked *