因为用的Archlinux,默认systemd启用,所以干脆用 systemd-networkd.service来管理DHCP获取ip地址,抛弃了dhcpcd@.service,ip地址是配置成功了,但是坑爹的是原本可以用的vpn服务突然连接不上了,取消 systemd-networkd.service换回dhcpcd@.service之后,一切都顺畅了。 摸索了好久,发现原来如此坑爹。。。
官网上:
http://www.freedesktop.org/software/systemd/man/systemd.network.html 里面有一句:
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. This controls the net.ipv4.conf.<interface>.forwarding and net.ipv6.conf.<interface>.forwarding sysctl options of the network interface (see ip-sysctl.txt for details about sysctl options). Defaults to "no".
Note: unless this option is turned on, no IP forwarding is done on this interface, even if this is globally turned on in the kernel, with the net.ipv4.ip_forward and net.ipv4.ip_forward sysctl options. Also, if this option is enabled for at least one interface, the global options in the kernel are also enabled as necessary, to ensure IP forwarding can take place.
IPMasquerade=
Configures IP masquerading for the network interface. If enabled packets forwarded from the network interface will be appear as coming from the local host. Takes a boolean argument. Implies IPForward=yes. Defaults to "no".
特别是这句话:
Note: unless this option is turned on, no IP forwarding is done on this interface, even if this is globally turned on in the kernel, with the net.ipv4.ip_forward and net.ipv4.ip_forward sysctl options.
也就是说,如果用systemd-networkd.service来配置ip地址,而且没有开启 IPForward=1 这个选项的话,ip转发就会失效(即使sysctl.conf里面配置了转发,systemd也会让它失效),也就意味着VPN能拨号,但是不能上网。
我真搞不明白,systemd到底要干什么。。。 原来的系统服务什么都被他给替代了。。。
另外有些程序需要系统获取ip地址之后才能够正常运行。。。 如果用systemd-networkd.service 配置网络,他是不管你ip地址有没有,就直接往下继续运行其他service,导致出问题。除非enable systemd-networkd-wait-online.service,而且还要给service特别设置
[Unit]
Requires=network-online.target
After=network-online.target
尤其影响的是openvpn@.service strongswan@.service.
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/186840
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.