For security reasons, IP forwarding is disabled by default in modern Linux operating systems. If you need to enable IP forwarding on your system, you need to perform the following steps. In this article, you will learn how to check whether IP forwarding is enabled. If not, how to enable it.
Check the current IP forwarding
Press the following command to check the value of ip_forward in/proc file system.
$ cat /proc/sys/net/ipv4/ip_forward 0
Or we can use the sysctl command line to query the kernel value, such as the following command.
$ sudo sysctl net.ipv4.ip_forward net.ipv4.ip_forward = 0
Enable Kernel IP Forwarding
Let us enable IP forwarding for the active shell of our current Linux system. These changes will be lost when the system is shut down or restarted.
$ echo 1 > /proc/sys/net/ipv4/ip_forward
Alternatively, we can use sysctl to enable it
$ sysctl -w net.ipv4.ip_forward=1
Enable kernel IP forwarding (permanent)
To enable IP forwarding, edit permanently /etc/sysctl.conf and add the following lines. This will enable IP forwarding even after a system reboot.
net.ipv4.ip_forward = 1
After adding the above values in sysctl.conf, use the following command to reload the values of this file.
$ sysctl -p
This article has ended here. For more exciting content, you can pay attention to thelinux video tutorialcolumn of the PHP Chinese website!
The above is the detailed content of How to enable IP forwarding on Linux. For more information, please follow other related articles on the PHP Chinese website!