我想让 systemd-networkd 仅管理 tun 接口的特定属性(DNS 服务器名称和搜索域),否则由 OpenVPN 客户端(分配 IP 地址)进行配置。为了实现这一目标,我使用以下网络单元文件:
[Match]
Name=ovpn
[Network]
DNS=10.0.0.1
Domains=lan
在此设置中,OpenVPN 客户端启动,连接到服务器,为 tun 接口分配 IP 地址,但该地址几乎立即从接口中删除。这可以在以下日志中看到:
systemd-networkd[18414]: ovpn: MAC address not found for new device, continuing without
systemd-networkd[18414]: ovpn: Flags change: +MULTICAST +POINTOPOINT +NOARP
systemd-networkd[18414]: ovpn: Link 36 added
systemd-networkd[18414]: ovpn: link pending udev initialization...
systemd-networkd[18414]: ovpn: Saved original MTU: 1500
systemd-networkd[18414]: ovpn: Flags change: +UP +LOWER_UP +RUNNING
systemd-networkd[18414]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_336 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=21 reply_cookie=0 error=n/a
systemd-networkd[18414]: ovpn: Gained carrier
systemd-networkd[18414]: ovpn: Adding address: fe80::49c6:c30b:5f86:6622/64 (valid forever)
systemd-networkd[18414]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_336 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=22 reply_cookie=0 error=n/a
systemd-networkd[18414]: ovpn: Gained IPv6LL
systemd-networkd[18414]: ovpn: Adding address: 10.1.1.100/22 (valid forever)
systemd-networkd[18414]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_336 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=23 reply_cookie=0 error=n/a
systemd-networkd[18414]: ovpn: udev initialized link
systemd-networkd[18414]: ovpn: Link state is up-to-date
systemd-networkd[18414]: ovpn: found matching network '/etc/systemd/network/ovpn.network'
systemd-networkd[18414]: ovpn: Discovering IPv6 routers
systemd-networkd[18414]: NDISC: Started IPv6 Router Solicitation client
systemd-networkd[18414]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_336 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=24 reply_cookie=0 error=n/a
systemd-networkd[18414]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_336 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=25 reply_cookie=0 error=n/a
systemd-networkd[18414]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_336 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=26 reply_cookie=0 error=n/a
systemd-networkd[18414]: NDISC: Sent Router Solicitation
systemd-networkd[18414]: ovpn: Removing address: 10.1.1.100/22 (valid forever)
为什么 IP 地址被删除?
我可以使用 systemd-networkd 仅管理网络接口的特定属性吗?
答案1
作为子出在 #systemd Freenode 的 irc 频道上发现了 Networkd 在链接(接口)状态方面的行为,该行为不是由 Networkd 本身设置的犯罪标题为networkd: link - 配置链接时删除外部配置带有以下提交消息(强调我的):
这是行为上的改变:
在我们永远不会删除任何状态之前,只会添加它,现在,我们在开始管理任何链接时都会删除不需要的状态。
但请注意,我们仍然不会删除运行时添加的任何外部状态,以避免任何反馈循环。然而,我们不保证与改变我们管理的链接状态的第三方工具共存。
最后,尝试在网络之外设置链接的属性并不是无竞争的。下面是系统启动的示例,其中事件顺序不同,最终结果是接口保留 OpenVPN 客户端设置的 IP 地址。
systemd-networkd[1047]: ovpn: MAC address not found for new device, continuing without
systemd-networkd[1047]: ovpn: Flags change: +MULTICAST +POINTOPOINT +NOARP
systemd-networkd[1047]: ovpn: Link 4 added
systemd-networkd[1047]: ovpn: udev initialized link
systemd-networkd[1047]: ovpn: Saved original MTU: 1500
systemd-networkd[1047]: ovpn: Link state is up-to-date
systemd-networkd[1047]: ovpn: found matching network '/etc/systemd/network/ovpn.network'
systemd-networkd[1047]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_34 interface= (...)
systemd-networkd[1047]: ovpn: Bringing link up
systemd-networkd[1047]: ovpn: IPv6 enabled for interface: Success
systemd-networkd[1047]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_34 interface= (...)
systemd-networkd[1047]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_34 interface= (...)
systemd-networkd[1047]: ovpn: Flags change: +UP +LOWER_UP +RUNNING
systemd-networkd[1047]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_34 interface= (...)
systemd-networkd[1047]: ovpn: Gained carrier
systemd-networkd[1047]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_34 interface= (...)
systemd-networkd[1047]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_34 interface= (...)
systemd-networkd[1047]: ovpn: Adding address: fe80::ba0:a13:d13d:d438/64 (valid forever)
systemd-networkd[1047]: Sent message type=signal sender=n/a destination=n/a object=/org/freedesktop/network1/link/_34 interface= (...)
systemd-networkd[1047]: ovpn: Gained IPv6LL
systemd-networkd[1047]: ovpn: Discovering IPv6 routers
systemd-networkd[1047]: NDISC: Started IPv6 Router Solicitation client
systemd-networkd[1047]: NDISC: Sent Router Solicitation
systemd-networkd[1047]: ovpn: Adding address: 10.1.1.100/22 (valid forever)