Home  >  Article  >  Operation and Maintenance  >  How to enable IP forwarding on Linux

How to enable IP forwarding on Linux

不言
不言Original
2019-03-25 15:51:294604browse

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.

How to enable IP forwarding on Linux

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 the linux video tutorial column 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn