$cat /proc/sys/net/ipv4/ip_forward 1
但转发仍然无法正常工作.我尝试在/etc/sysctl.conf中添加net.ipv4.conf.default.forwarding = 1.现在重启后我有了
$cat /proc/sys/net/ipv4/ip_forward 1 $cat /proc/sys/net/ipv4/conf/default/forwarding 1 $cat /proc/sys/net/ipv4/conf/all/forwarding 1 $cat /proc/sys/net/ipv4/conf/enp0s3/forwarding 0 $cat /proc/sys/net/ipv4/conf/tun0/forwarding 0
我无法在sysctl.conf中启用/ proc / sys / net / ipv4 / conf / enp0s3 / forwarding和/ proc / sys / net / ipv4 / conf / tun0 / forwarding,因为这些文件在这样的早期启动时不存在:
systemd-sysctl[85]: Couldn't write '1' to 'net/ipv4/conf/enp0s3/forwarding',ignoring: No such file or directory systemd-sysctl[85]: Couldn't write '1' to 'net/ipv4/conf/tun0/forwarding',ignoring: No such file or directory)
如果我手动启用enp0s3和tun0的转发,则转发按预期工作.
那么,如何正确启用接口转发?
PS:内核4.1.15和systemd 226的Gentoo
PPS:如果我的记忆在一段时间之前为我服务,net.ipv4.ip_forward = 1就足够了.
解决方法
我使用systemd(带网络)和systemd-221中引入了关于ip转发的新功能:“IPForwarding =” – 见 https://github.com/systemd/systemd/blob/a2088fd025deb90839c909829e27eece40f7fce4/NEWS
来自man systemd.network:
[NETWORK] SECTION OPTIONS
…
IPForward=
Configures IP forwarding for the network interface. If enabled incoming packets on the network interface will be forwarded to other interfaces according to the routing table. Takes either a boolean argument,or the values “ipv4” or “ipv6”,which only enables IP forwarding for the specified address family,or “kernel”,which preserves existing sysctl settings. This controls the net.ipv4.conf..forwarding and net.ipv6.conf..forwarding sysctl options of the network interface (see ip-sysctl.txt[1] for details about sysctl options). Defaults to “no”.
Note: unless this option is turned on,or set to “kernel”,no IP forwarding is done on this interface,even if this is globally turned on in the kernel,with the net.ipv4.ip_forward,net.ipv4.conf.all.forwarding,and net.ipv6.conf.all.forwarding sysctl options.
所以现在我使用如下的网络文件来启用ip转发(每个接口):
# cat /etc/systemd/network/tun0.network [Match] Name=tun0 [Network] IPForward=ipv4