新的 IP 地址,而 DHCP 租约超时

新的 IP 地址,而 DHCP 租约超时

我的嵌入式系统使用 systemd 并通过 DHCP 获取其 IP 地址。如果遵守租用时间,则 DHCP 服务器使用租用时间为网络上的每台计算机提供相同的 IP 唯一地址。

我的嵌入式系统的网络配置如下:

/etc/systemd/network/dhcp.network

[Match]
Name=eth*

[Network]
DHCP=yes

问题是每次启动时,我的系统都会获得一个新的 IP 地址。我缺少一些配置吗?

更多信息:

$ cat /proc/version
Linux version 4.16.0 ([email protected]) (gcc version 7.3.0 (Buildroot 2018.05-g0164235-dirty)) #18 SMP PREEMPT Tue Jul 17 14:28:37 CEST 2018  

[编辑] 添加 DHCP 发现包

Frame 13299: 327 bytes on wire (2616 bits), 327 bytes captured (2616 bits) on interface 0  
    Interface id: 0 (\\.\pipe\Shamrock_Wireshark_TAP__30815)  
    Encapsulation type: Ethernet (1)  
    Arrival Time: Jul 16, 2018 10:39:49.166800000 Paris, Madrid (heure d??t?)  
    [Time shift for this packet: 0.000000000 seconds]  
    Epoch Time: 1531730389.166800000 seconds  
    [Time delta from previous captured frame: 20.554641000 seconds]  
    [Time delta from previous displayed frame: 43.658782000 seconds]  
    [Time since reference or first frame: 43.770160000 seconds]  
    Frame Number: 13299  
    Frame Length: 327 bytes (2616 bits)  
    Capture Length: 327 bytes (2616 bits)  
    [Frame is marked: False]  
    [Frame is ignored: False]  
    [Protocols in frame: eth:ethertype:ip:udp:bootp]  
    [Coloring Rule Name: UDP]  
    [Coloring Rule String: udp]  
Ethernet II, Src: AlstomGr_20:00:6f (80:b3:2a:20:00:6f), Dst: Broadcast (ff:ff:ff:ff:ff:ff)  
    Destination: Broadcast (ff:ff:ff:ff:ff:ff)  
        Address: Broadcast (ff:ff:ff:ff:ff:ff)  
        .... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)  
        .... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)  
    Source: AlstomGr_20:00:6f (80:b3:2a:20:00:6f)  
        Address: AlstomGr_20:00:6f (80:b3:2a:20:00:6f)  
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)  
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)  
    Type: IPv4 (0x0800)
Internet Protocol Version 4, Src: 0.0.0.0, Dst: 255.255.255.255  
    0100 .... = Version: 4  
    .... 0101 = Header Length: 20 bytes  
    Differentiated Services Field: 0xc0 (DSCP: CS6, ECN: Not-ECT)  
        1100 00.. = Differentiated Services Codepoint: Class Selector 6 (48)  
        .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0)  
    Total Length: 313  
    Identification: 0x0000 (0)  
    Flags: 0x00  
        0... .... = Reserved bit: Not set  
        .0.. .... = Don't fragment: Not set  
        ..0. .... = More fragments: Not set  
    Fragment offset: 0  
    Time to live: 64  
    Protocol: UDP (17)  
    Header checksum: 0x78f5 [validation disabled]  
        [Good: False]  
        [Bad: False]  
    Source: 0.0.0.0  
    Destination: 255.255.255.255  
    [Source GeoIP: Unknown]  
    [Destination GeoIP: Unknown]  
User Datagram Protocol, Src Port: 68 (68), Dst Port: 67 (67)  
    Source Port: 68  
    Destination Port: 67  
    Length: 293  
    Checksum: 0xca77 [validation disabled]  
        [Good Checksum: False]  
        [Bad Checksum: False]  
    [Stream index: 0]   
Bootstrap Protocol (Discover)  
    Message type: Boot Request (1)  
    Hardware type: Ethernet (0x01)  
    Hardware address length: 6  
    Hops: 0  
    Transaction ID: 0x240b826b  
    Seconds elapsed: 1  
    Bootp flags: 0x0000 (Unicast)  
        0... .... .... .... = Broadcast flag: Unicast  
        .000 0000 0000 0000 = Reserved flags: 0x0000  
    Client IP address: 0.0.0.0  
    Your (client) IP address: 0.0.0.0  
    Next server IP address: 0.0.0.0  
    Relay agent IP address: 0.0.0.0  
    Client MAC address: AlstomGr_20:00:6f (80:b3:2a:20:00:6f)  
    Client hardware address padding: 00000000000000000000  
    Server host name not given  
    Boot file name not given  
    Magic cookie: DHCP  
    Option: (53) DHCP Message Type (Discover)  
        Length: 1  
        DHCP: Discover (1)  
    Option: (61) Client identifier  
        Length: 19  
        IAID: cd4578d2  
        DUID Type: assigned by vendor based on Enterprise number (2)  
        Enterprise-number: Tom Gundersen (systemd) (43793)  
        Identifier: 871468cb35ae1ddc  
    Option: (55) Parameter Request List  
        Length: 8  
        Parameter Request List Item: (1) Subnet Mask  
        Parameter Request List Item: (3) Router  
        Parameter Request List Item: (12) Host Name  
        Parameter Request List Item: (15) Domain Name  
        Parameter Request List Item: (6) Domain Name Server  
        Parameter Request List Item: (33) Static Route  
        Parameter Request List Item: (121) Classless Static Route  
        Parameter Request List Item: (42) Network Time Protocol Servers  
    Option: (57) Maximum DHCP Message Size  
        Length: 2  
        Maximum DHCP Message Size: 576  
    Option: (12) Host Name  
        Length: 4  
        Host Name: RPH4  
    Option: (255) End  
        Option End: 255

答案1

DHCP 发现数据包包含 RFC 4361 样式的客户端标识符(选项 61,也称为 DUID)以及systemd企业编号 (43793)。这是因为你的/etc/systemd/network/dhcp.network文件不包含ClientIdentifiernorDUIDType设置;默认值是ClientIdentifier=duidDUIDType=vendor

默认设置DUIDType=vendorsystemd-networkd使用上述企业号和 的哈希内容生成 DUID /etc/machine-id。它们machine-id应该在系统首次启动时生成,然后在系统的生命周期内(或至少在操作系统安装的生命周期内)保持不变。

如果您的嵌入式系统未配置为machine-id持久存储它,它将在每次启动时随机生成......这将导致您所看到的行为。

如果您不需要系统使用符合 IPv6 的 DUID 标识符,最简单的解决方法是指定该系统应使用其 MAC 地址作为 DHCP 客户端标识符。这可以通过将其添加到您的dhcp.network文件中来实现:

[DHCP]
ClientIdentifier=mac

如果您还使用 DHCPv6,和/或需要使用特定于系统而不是其特定 NIC 的标识符来识别 DHCP 客户端,那么您应该阅读systemd网络配置文件的文档并找到适合您需求的设置组合。

相关内容