18.04 服务器 Systemd DHCP 在 DISCOVER 上挂起,dhclient 可以工作

18.04 服务器 Systemd DHCP 在 DISCOVER 上挂起,dhclient 可以工作

刚刚安装了 ubuntu server 18.04。我无法使用 systemd-networkd 获取 dhcp 租约,但使用 dhclient 可以正常工作。

使用 SYSTEMD_LOG_LEVEL=debug 我得到:

$ journalctl
...
Apr 29 10:14:09 computer systemd-networkd[2169]: enp3s0: Link state is up-to-date
Apr 29 10:14:09 computer systemd-networkd[2169]: enp3s0: found matching network '/etc/systemd/network/10-netplan-enp3s0.network'
Apr 29 10:14:09 computer systemd-networkd[2169]: wlp2s0: Link is not managed by us
Apr 29 10:14:09 computer systemd-networkd[2169]: lo: Link is not managed by us
Apr 29 10:14:09 computer systemd-networkd[2169]: LLDP: Started LLDP client
Apr 29 10:14:09 computer systemd-networkd[2169]: enp3s0: Started LLDP.
Apr 29 10:14:09 computer systemd-networkd[2169]: enp3s0: Acquiring DHCPv4 lease
Apr 29 10:14:09 computer systemd-networkd[2169]: DHCP CLIENT (0xb7fc15eb): STARTED on ifindex 2
Apr 29 10:14:09 computer systemd-networkd[2169]: enp3s0: Discovering IPv6 routers
Apr 29 10:14:09 computer systemd-networkd[2169]: NDISC: Started IPv6 Router Solicitation client
Apr 29 10:14:09 computer systemd-networkd[2169]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/network1/link/_32 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=9 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a
Apr 29 10:14:09 computer systemd-networkd[2169]: NDISC: Sent Router Solicitation, next solicitation in 4s
Apr 29 10:14:09 computer systemd-networkd[2169]: DHCP CLIENT (0xb7fc15eb): DISCOVER
Apr 29 10:14:09 computer systemd-networkd[2169]: lo: Link state is up-to-date
Apr 29 10:14:09 computer systemd-networkd[2169]: lo: Unmanaged
Apr 29 10:14:09 computer systemd-networkd[2169]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/network1/link/_31 interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=10 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a
Apr 29 10:14:09 computer systemd-timesyncd[581]: Network configuration changed, trying to establish connection.
Apr 29 10:14:09 computer sudo[2164]: pam_unix(sudo:session): session closed for user root
Apr 29 10:14:11 computer systemd-networkd[2169]: DHCP CLIENT (0xb7fc15eb): DISCOVER
Apr 29 10:14:12 computer systemd-networkd[2169]: DHCP CLIENT (0xb7fc15eb): DISCOVER
Apr 29 10:14:14 computer systemd-networkd[2169]: NDISC: Sent Router Solicitation, next solicitation in 8s
Apr 29 10:14:16 computer systemd-networkd[2169]: DHCP CLIENT (0xb7fc15eb): DISCOVER
Apr 29 10:14:21 computer systemd-networkd[2169]: NDISC: No RA received before link confirmation timeout
Apr 29 10:14:21 computer systemd-networkd[2169]: NDISC: Invoking callback for 't'.
Apr 29 10:14:22 computer systemd-networkd[2169]: NDISC: Sent Router Solicitation, next solicitation in 17s
Apr 29 10:14:25 computer systemd-networkd[2169]: DHCP CLIENT (0xb7fc15eb): DISCOVER
Apr 29 10:14:39 computer systemd-networkd[2169]: NDISC: Sent Router Solicitation, next solicitation in 34s
Apr 29 10:14:41 computer systemd-networkd[2169]: DHCP CLIENT (0xb7fc15eb): DISCOVER
Apr 29 10:15:14 computer systemd-networkd[2169]: NDISC: Sent Router Solicitation, next solicitation in 1min 10s
Apr 29 10:15:14 computer systemd-networkd[2169]: DHCP CLIENT (0xb7fc15eb): DISCOVER
Apr 29 10:16:18 computer systemd-networkd[2169]: DHCP CLIENT (0xb7fc15eb): DISCOVER

当我使用 dhcpd 时一切正常:

Apr 29 10:33:00 computer sudo[2213]:    user : TTY=tty1 ; PWD=/home/user ; USER=root ; COMMAND=/sbin/dhclient -v enp3s0
Apr 29 10:33:00 computer sudo[2213]: pam_unix(sudo:session): session opened for user root by user(uid=0)
Apr 29 10:33:00 computer dhclient[2214]: Internet Systems Consortium DHCP Client 4.3.5
Apr 29 10:33:00 computer dhclient[2214]: Copyright 2004-2016 Internet Systems Consortium.
Apr 29 10:33:00 computer dhclient[2214]: All rights reserved.
Apr 29 10:33:00 computer dhclient[2214]: For info, please visit https://www.isc.org/software/dhcp/
Apr 29 10:33:00 computer dhclient[2214]:
Apr 29 10:33:00 computer dhclient[2214]: Listening on LPF/enp3s0/c0:3f:d5:63:0a:30
Apr 29 10:33:00 computer dhclient[2214]: Sending on   LPF/enp3s0/c0:3f:d5:63:0a:30
Apr 29 10:33:00 computer dhclient[2214]: Sending on   Socket/fallback
Apr 29 10:33:00 computer dhclient[2214]: DHCPDISCOVER on enp3s0 to 255.255.255.255 port 67 interval 3 (xid=0x536ea71d)
Apr 29 10:33:02 computer dhclient[2214]: DHCPREQUEST of 192.168.64.102 on enp3s0 to 255.255.255.255 port 67 (xid=0x1da76e53)
Apr 29 10:33:02 computer dhclient[2214]: DHCPOFFER of 192.168.64.102 from 192.168.64.1
Apr 29 10:33:02 computer dhclient[2214]: DHCPACK of 192.168.64.102 from 192.168.64.1
Apr 29 10:33:02 computer systemd-networkd[2169]: enp3s0: Adding address: 192.168.64.102/24 (valid forever)

我的问题是:

  • 有谁见过这种情况并且知道其原因是什么吗?
  • 有什么方法可以找出它无法与 dhcp 服务器通信的原因吗?
  • 有没有一种安全的方法(对系统更新具有鲁棒性)来让它使用 dhclient?

在我必须离开之前,我只有有限的时间来让它工作,并且我需要知道它在重新启动时无需本地干预即可重新上线。

编辑:所需信息:

$ sudo lshw -C network  
*-network DISABLED        
       description: Wireless interface
       product: Wireless 7260
       vendor: Intel Corporation
       physical id: 0
       bus info: pci@0000:02:00.0
       logical name: wlp2s0
       version: 73
       serial: ac:7b:a1:43:12:c8
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless
       configuration: broadcast=yes driver=iwlwifi driverversion=4.15.0-48-generic firmware=17.948900127.0 latency=0 link=no multicast=yes wireless=IEEE 802.11
       resources: irq:92 memory:d0700000-d0701fff
  *-network
       description: Ethernet interface
       product: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0
       bus info: pci@0000:03:00.0
       logical name: enp3s0
       version: 0c
       serial: c0:3f:d5:63:0a:30
       size: 100Mbit/s
       capacity: 1Gbit/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress msix vpd bus_master cap_list ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=2.3LK-NAPI duplex=full firmware=rtl8168g-2_0.0.1 02/06/13 ip=192.168.64.102 latency=0 link=yes multicast=yes port=MII speed=100Mbit/s
       resources: irq:18 ioport:e000(size=256) memory:d0604000-d0604fff memory:d0600000-d0603fff

网络计划:

$ cat /etc/netplan/*.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5). 
network:   
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: true

还:

$ cat /run/systemd/network/*
[Match]
Name=enp3s0

[Network]
DHCP=ipv4
LinkLocalAddressing=ipv6

[DHCP]
UseMTU=true
RouteMetric=100

我也尝试过不使用 [DHCP] 节和 LinkLocalAddressing 行(当然这没关系),但无济于事。

谢谢。

编辑 2:在设置的后期阶段,我需要设置一个 pppoe 接口。我现在意识到 netplan 和 networkd 不支持 pppoe 配置,所以我放弃了这个,回到了 NetworkManager。

答案1

我遇到了完全一样的问题。虽然这个问题已经 6 个月了,但我认为它可能对其他人有帮助,所以我在这里发布了我的解决方案。

我运行了 tcpdump( tcpdump -n ether host <mac> and port 67 and port 68 -vvv) 来检查 networkd 和 dhclient 发送的 DHCP Discover 数据包中的差异,发现 networkd 设置的 Client ID 是一个自己生成的 18 字节 ID 作为 Client ID,但 dhclient 只是 MAC 地址。

DHCP 服务器可能需要客户端 ID 上的 MAC 地址。

dhcp-identifier: mac因此可以通过在 netplan 配置中添加以下内容来解决问题,例如:

network:   
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: true
      dhcp-identifier: mac

相关内容