How to enable IP forwarding on Linux (IPv4 / IPv6)

How to enable IP forwarding on Linux (IPv4 / IPv6)?
Tutorials / October 21, 2020
Introduction
IP forwarding is the ability for an operating system to accept incoming network packets on one interface, identifying that it is not meant for the system itself, but it should be forwarded on to another network, and then onwards accordingly.

By default, any latest Linux distributions will have IP Forwarding disabled. Thus, it is a good idea, as many users will not need IP Forwarding, but, What if we are setting up a Linux router/gateway or a VPN server or simply a plain dial-in server then we must need to enable forwarding.

IP Forwarding Overview
In this tutorial we will see how to enable IP forwarding on Linux, it is a fairly simple procedure and we will learn how to make this temporary or permanent on the system. IP forwarding enables an operating system (here on Linux) to forward packets as a router does or more generally to route them through other networks. The activation of IP forwarding is often used when listening to the network (Man in the middle attack in particular) but also more simply when trying to make a Linux machine a router between several networks.

Let’s check out how to Enable IP Forwarding:

Firstly, we need to check the Current IP forwarding status.

Check if IP Forwarding is enabled or not:

Here we have to query the sysctl kernel value net.ipv4.ip_forward to check if IP forwarding is enabled or not: Using sysctl:

sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0

Or just check out the value in the /proc system:

cat /proc/sys/net/ipv4/ip_forward
0

在这里插入图片描述

As per the above examples, we can see this was disabled (as shown by the value 0).

Temporary Activation
The activation and deactivation of IP forwarding, in IPv4, as does IPv6 is handled in /proc files. This is “/proc/sys/net/ipv4/ip_forward” for IPv4 and “/proc/sys/net/ipv6/conf/all/forwarding” for IPv6.

If we do a “cat” on these files, we will see that they are by default to 0, to activate the IP forwarding temporarily, it is enough to put them at 1. One can then modify the file or use the “sysctl” command:

| sysctl -w net.ipv4.ip_forward=1

在这里插入图片描述

Or, following is one more command to enable temporary:

| echo 1 > /proc/sys/net/ipv4/ip_forward

The temporary change, of course, means that the parameters will return to their default value when the machine restarts or “sysctl” restarts if it is done manually.

Now, let’s check out the Permanent Solution for it.

Permanent Activation
To enable these changes permanently, you have to modify the configuration file of sysctl so that it loads our modifications each start. It is the file “/etc/sysctl.conf” to activate IPv4 IP forwarding. We will add or uncomment this line:

| net.ipv4.ip_forward = 1

For IPv6, we will do the same with this line:

| net.ipv6.conf.all.forwarding=1

The configuration can then be reloaded so that the changes take effect immediately:

| sysctl -p /etc/sysctl.conf

在这里插入图片描述

That’s it! You have successfully performed the activation.

Happy Learning!

【转】https://www.eukhost.com/kb/how-to-enable-ip-forwarding-on-linux-ipv4-ipv6/

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值