我想用它systemd-networkd
来配置我的 Ubuntu 网络。
我添加了一个/etc/systemd/network/host0.network
文件
[Match]
Name=host0
[Network]
Address=10.5.1.1/24
Gateway=10.5.1.254
配置我的host0
:
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: host0@if14428: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether d6:fa:2e:69:dd:30 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 169.254.229.86/16 brd 169.254.255.255 scope link host0
valid_lft forever preferred_lft forever
inet6 fe80::d4fa:2eff:fe69:dd30/64 scope link
valid_lft forever preferred_lft forever
但是,如上所示,10.5.1.1
尽管重新启动systemd-networkd
、启用它、重新启动,它仍未配置。每次地址都来自 APIPA(好像没有 DHCP,它没有在那里配置)。
其他地方均未配置网络(尤其是/etc/network/interfaces
,其中为空)
答案1
从https://coreos.com/os/docs/latest/network-config-with-networkd.html:
手动启用调试
mkdir -p /etc/systemd/system/systemd-networkd.service.d/
/etc/systemd/system/systemd-networkd.service.d/10-debug.conf
创建包含以下内容的Drop-In :
[Service]
Environment=SYSTEMD_LOG_LEVEL=debug
并重启systemd-networkd
服务:
systemctl daemon-reload
systemctl restart systemd-networkd
journalctl -b -u systemd-networkd
答案2
如何调试 systemd-networkd?
使用以下方式激活调试日志记录service-log-level
您可以利用systemctl
的service-log-level
命令:
# set current log level of systemd-networkd.service to "debug":
systemctl service-log-level systemd-networkd.service debug
# syntax:
# systemctl service-log-level SERVICE [LEVEL]
# LEVEL:
# a value in the range 0…7
# or one of the strings emerg, alert, crit, err, warning, notice, info, debug
# check current log level of systemd-networkd.service by not specifying a level:
systemctl service-log-level systemd-networkd.service
监视/查看systemd-networkd.service
日志
日志systemd-networkd.service
然后可以使用以下命令监视特定的日志条目:
journalctl --unit=systemd-networkd.service --follow
# or short
journalctl -u systemd-networkd -f
例子日志日志条目带有“systemd-networkd 登录调试级别“networkctl renew eth0
在我的系统上执行时:
Sep 08 13:45:43 abdull systemd-networkd[572]: Got message type=method_call sender=:1.31 destination=org.freedesktop.network1 path=/org/freedesktop/network1 interface=org.freedesktop.network1.Manager member=RenewLink cookie=2 reply_cookie=0 signature=i error-name=n/a error-message=n/a
Sep 08 13:45:43 abdull systemd-networkd[572]: Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=GetConnectionUnixUser cookie=59 reply_cookie=0 signature=s error-name=n/a error-message=n/a
Sep 08 13:45:43 abdull systemd-networkd[572]: Got message type=method_return sender=org.freedesktop.DBus destination=:1.15 path=n/a interface=n/a member=n/a cookie=17 reply_cookie=59 signature=u error-name=n/a error-message=n/a
Sep 08 13:45:43 abdull systemd-networkd[572]: Sent message type=method_return sender=n/a destination=:1.31 path=n/a interface=n/a member=n/a cookie=60 reply_cookie=2 signature=n/a error-name=n/a error-message=n/a
Sep 08 13:45:43 abdull systemd-networkd[572]: DHCP CLIENT (0x359abcde): REQUEST (renewing)
Sep 08 13:45:43 abdull systemd-networkd[572]: DHCP CLIENT (0x359abcde): ACK
Sep 08 13:45:43 abdull systemd-networkd[572]: DHCP CLIENT (0x359abcde): lease expires in 59min 58s
Sep 08 13:45:43 abdull systemd-networkd[572]: DHCP CLIENT (0x359abcde): T2 expires in 49min 25s
Sep 08 13:45:43 abdull systemd-networkd[572]: DHCP CLIENT (0x359abcde): T1 expires in 26min 54s
Sep 08 13:45:43 abdull systemd-networkd[572]: eth0: State changed: configured -> configuring
Sep 08 13:45:43 abdull systemd-networkd[572]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/network1/link/_32 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=61 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a
Sep 08 13:45:43 abdull systemd-networkd[572]: eth0: Updating address: 10.0.3.165
Sep 08 13:45:43 abdull systemd-networkd[572]: eth0: Remembering updated address: 10.0.3.165/24 (valid for 1h)
Sep 08 13:45:43 abdull systemd-networkd[572]: eth0: link_check_ready(): static routes are not configured.
Sep 08 13:45:43 abdull systemd-networkd[572]: eth0: DHCP: No routes received from DHCP server: No data available
Sep 08 13:45:43 abdull systemd-networkd[572]: eth0: Configuring route: dst: 10.0.3.1/32, src: n/a, gw: n/a, prefsrc: 10.0.3.165, scope: link, table: main, proto: dhcp, type: unicast
Sep 08 13:45:43 abdull systemd-networkd[572]: eth0: Configuring route: dst: n/a, src: n/a, gw: 10.0.3.1, prefsrc: 10.0.3.165, scope: global, table: main, proto: dhcp, type: unicast
Sep 08 13:45:43 abdull systemd-networkd[572]: eth0: link_check_ready(): dhcp4:no dhcp6_addresses:no dhcp_routes:no dhcp_pd_addresses:no dhcp_pd_routes:no ndisc_addresses:yes ndisc_routes:yes
Sep 08 13:45:43 abdull systemd-networkd[572]: eth0: State changed: configuring -> configured
Sep 08 13:45:43 abdull systemd-networkd[572]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/network1/link/_32 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=62 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a
而当systemd-networkd.service
处于默认日志级别时,在我的系统上info
执行时没有日志条目。networkctl renew eth0
比较这 service-log-level
解决方案和插入解决方案:
service-log-level |
插入 | |
---|---|---|
需要/暗示systemctl daemon-reload |
没有✔️ | 是的❌ |
需要systemd-networkd.service 重新启动 |
没有✔️ | 是的❌ |
配置持续后systemd-networkd.service |
不❌ | 是的✔️ |
计算机重启后配置仍然存在 | 不❌ | 是的✔️ |
简单的一行程序即可打开或关闭调试 | 是的✔️ | 不❌ |
注意:复选标记(✔️)和十字标记(❌)字符表示可取或不可取的特征(取决于上下文)。
答案3
前面的答案对于找出哪些正在运行、哪些没有运行以及重新启动服务非常有用。
我想补充一下(来自如果已禁用,如何启用):
systemctl enable <your.service.here>
例如systemd-networkd
另外,我不确定Name=host0
匹配的内容。我猜是匹配,因为它出现在2: host0@if14428
下ip addr
。但使用 和接口名称或 MAC 地址(如 中所示)ip link
是更安全的选择。