dhcpd 在重启后不发出相同的租约

dhcpd 在重启后不发出相同的租约

我正在运行由 Yocto(Zeus,3.0.0)构建的 4.14.149,并且我们正在提取 dhcpd 的 OpenEmbedded 版本(我认为是 4.4.1 版本)。

这是我的配置文件:

#
# DHCPd config for private network
#

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# Set the lease time to 6 hours so the 'dhcp.leases' file grows slowly
default-lease-time 21600;
max-lease-time 21600;

# This is a very basic subnet declaration. Address .201 and above can be used
# for static IP assignment
subnet 10.0.0.0 netmask 255.255.255.0 {
  range 10.0.0.2 10.0.0.200;
}

我看到的是,如果我将另一块板连接到它,它会正确获得一个 IP 地址。但是,如果我重新启动连接的设备,它会获得不同的 IP 地址。如果我查看租约文件,我会注意到 UID 不同,即使它是完全相同的设备:

root@alvaFHABeeprom:~# cat /var/lib/dhcp-private/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.4.1

# authoring-byte-order entry is generated, DO NOT DELETE
authoring-byte-order little-endian;

server-duid "\000\001\000\001'\221\321\015\002\220\233n\366\303";

lease 10.0.0.2 {
  starts 3 2021/01/13 15:43:02;
  ends 3 2021/01/13 21:43:02;
  cltt 3 2021/01/13 15:43:02;
  binding state active;
  next binding state free;
  rewind binding state free;
  hardware ethernet 00:0a:55:02:27:3e;
  uid "\377(\376\362\321\000\002\000\000\253\021d~N\310\030\210G\356";
  client-hostname "alva-UI";
}
lease 10.0.0.3 {
  starts 3 2021/01/13 15:44:13;
  ends 3 2021/01/13 21:44:13;
  cltt 3 2021/01/13 15:44:13;
  binding state active;
  next binding state free;
  rewind binding state free;
  hardware ethernet 00:0a:55:02:27:3e;
  uid "\377(\376\362\321\000\002\000\000\253\021tl\350s\205\3666E";
  client-hostname "alva-UI";
}
root@alvaFHABeeprom:~#

如何让完全相同的设备在重启后拥有相同的地址?我尝试将其添加one-lease-per-client true;到我的 dhcpd 配置中,但似乎没有帮助。

答案1

( DHCPuid客户端标识符)似乎是由systemd-networkdDHCP 客户端:

\377(\376\362\321\000\002\000\000\253\021tl\350s\205\3666E
字节 价值
\377 DHCP 客户端 ID 类型:N/A (255) – 包含 RFC 4361 嵌入式 DHCPv6 IAID+DUID
(\376\362\321 DHCPv6 IAID:28:FE:F2:D1
\000\002 DHCPv6 DUID 类型:DUID-EN (2) – 供应商特定
\000\000\253\021 DUID-EN 私有企业编号:systemd (43793)
d~N\310\030\210G\356 DUID-EN 供应商特定数据:64:7E:4E:C8:18:88:47:EE

在 systemd-networkd 中,DHCPv6 DUID-EN(以及 DHCP 客户端标识符)是通过对存储在机器编号文件。如果此文件缺失且/etc为只读,则每次启动时都会生成不同的 ID(由systemd-机器 ID 设置服务)。

理想情况下,此文件应在重启后继续存在 - 如果您的 /etc 位于只读文件系统,则将该文件符号链接到 /var 或其他持久位置。

一个更简单的修复方法(但仅适用于 DHCP)是将客户端配置为从 MAC 地址生成其 DHCP 客户端标识符:

[DHCPv4]
# This disables DHCPv6 DUID usage in DHCPv4 completely, and uses
# the traditional client ID type 0x01 (Ethernet MAC address).
ClientIdentifier=mac

[DHCPv6]
DUIDType=link-layer

不建议忽略 DHCP 服务器中的客户端 ID。

答案2

所以我无法解释为什么每次启动时 UID 都不同,但添加ignore-client-uids true;到我的配置中就可以解决这个问题。

不幸的是,我在发布这个问题后发现了这一点,但这是解决方案概述:https://serverfault.com/questions/694351/how-do-i-keep-isc-dhcpd-from-offering-different-ips-when-there-is-two-requests-f

相关内容