![Ubuntu DHCP 客户端使用 ID 而不是 MAC 地址。无法更改此行为](https://linux22.com/image/954676/Ubuntu%20DHCP%20%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%20ID%20%E8%80%8C%E4%B8%8D%E6%98%AF%20MAC%20%E5%9C%B0%E5%9D%80%E3%80%82%E6%97%A0%E6%B3%95%E6%9B%B4%E6%94%B9%E6%AD%A4%E8%A1%8C%E4%B8%BA.png)
我正在尝试使用 DHCP 静态租约分配,而不是手动管理某些服务器的静态 IP。然而,Ubuntu 从 MAC 地址切换到某些 DHCP ID,在操作系统发生重大变化导致获得新的 DHCP 租约后,这些 ID 变得毫无用处。至少在 18.04-23.04 上可以看到这一点。
谷歌搜索后发现在 /etc/dhcp/dhclient.conf 中添加了“send dhcp-client-identifier = hardware;”但这不起作用。
Windows 和 Mac 机器仍然使用 MAC 地址。不知道为什么 Ubuntu 特别针对服务器发行版更改了此机制。
答案1
如果您的 dhcp 服务器配置为根据 MAC(机器地址代码)提供一些 IP 地址,则应Client-ID
忽略,而不管它是什么。如果您的 Windows dhcp 服务器正在使用Client-ID
您要求它根据 MAC 分配 IP 地址,那么这将是一个问题。我只使用过基于 Linux 的 dhcp 服务器,自从我第一次在 Ubuntu 10.04 版中使用它以来,它在基于 MAC 的 IP 地址分配方面一直运行良好。
是的,Ubuntu 现在默认提供了一个Client-ID
不是 MAC 的版本(我认为从 16.04 到 18.04 版本之间开始)。示例来自 20.04 测试服务器客户端,希望经过编辑以便更清晰:
doug@s15:~$ sudo tcpdump -n -tttt -i br0 -vv port 67
tcpdump: listening on br0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
2023-12-31 08:30:22.423734 IP (tos 0xc0, ttl 64, id 0, offset 0, flags [none], proto UDP (17), length 315)
0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 3c:7c:3f:0d:99:83, length 287, xid 0x9399bc4d, secs 1, Flags [none] (0x0000)
Client-Ethernet-Address 3c:7c:3f:0d:99:83
...
DHCP-Message (53), length 1: Discover
Client-ID (61), length 19: hardware-type 255, 30:d1:36:0b:00:02:00:00:ab:11:c2:7e:3e:b1:15:66:00:36
...
2023-12-31 08:30:22.423962 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
192.168.111.1.67 > 192.168.111.136.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0x9399bc4d, secs 1, Flags [none] (0x0000)
Your-IP 192.168.111.136
Client-Ethernet-Address 3c:7c:3f:0d:99:83
...
DHCP-Message (53), length 1: Offer
...
2023-12-31 08:30:22.424291 IP (tos 0xc0, ttl 64, id 0, offset 0, flags [none], proto UDP (17), length 327)
0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 3c:7c:3f:0d:99:83, length 299, xid 0x9399bc4d, secs 1, Flags [none] (0x0000)
Client-Ethernet-Address 3c:7c:3f:0d:99:83
...
DHCP-Message (53), length 1: Request
Client-ID (61), length 19: hardware-type 255, 30:d1:36:0b:00:02:00:00:ab:11:c2:7e:3e:b1:15:66:00:36
...
2023-12-31 08:30:22.424463 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
192.168.111.1.67 > 192.168.111.136.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0x9399bc4d, secs 1, Flags [none] (0x0000)
Your-IP 192.168.111.136
Client-Ethernet-Address 3c:7c:3f:0d:99:83
...
DHCP-Message (53), length 1: ACK
请注意客户端 ID 为:
30:d1:36:0b:00:02:00:00:ab:11:c2:7e:3e:b1:15:66:00:36
现在,如果我添加dhcp-identifier: mac
到我的/etc/netplan/01-netcfg.yaml
文件(你的文件可能有不同的名称),例如:
doug@s19:~/config/etc/netplan$ cat 01-netcfg.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: no
bridges:
br0:
interfaces: [ enp3s0 ]
dhcp4: yes
dhcp-identifier: mac
然后我得到:
doug@s15:~$ sudo tcpdump -n -tttt -i br0 -vv port 67
tcpdump: listening on br0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
2023-12-31 11:42:59.901076 IP (tos 0xc0, ttl 64, id 0, offset 0, flags [none], proto UDP (17), length 303)
0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 3c:7c:3f:0d:99:83, length 275, xid 0x8418f444, secs 1, Flags [none] (0x0000)
Client-Ethernet-Address 3c:7c:3f:0d:99:83
...
DHCP-Message (53), length 1: Discover
Client-ID (61), length 7: ether 3c:7c:3f:0d:99:83
...
2023-12-31 11:42:59.903551 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
192.168.111.1.67 > 192.168.111.136.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0x8418f444, secs 1, Flags [none] (0x0000)
Your-IP 192.168.111.136
Client-Ethernet-Address 3c:7c:3f:0d:99:83
...
DHCP-Message (53), length 1: Offer
...
2023-12-31 11:42:59.903851 IP (tos 0xc0, ttl 64, id 0, offset 0, flags [none], proto UDP (17), length 315)
0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 3c:7c:3f:0d:99:83, length 287, xid 0x8418f444, secs 1, Flags [none] (0x0000)
Client-Ethernet-Address 3c:7c:3f:0d:99:83
...
DHCP-Message (53), length 1: Request
Client-ID (61), length 7: ether 3c:7c:3f:0d:99:83
...
2023-12-31 11:42:59.904052 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
192.168.111.1.67 > 192.168.111.136.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0x8418f444, secs 1, Flags [none] (0x0000)
Your-IP 192.168.111.136
Client-Ethernet-Address 3c:7c:3f:0d:99:83
...
DHCP-Message (53), length 1: ACK
请注意,现在客户端 ID 是 MAC:
3c:7c:3f:0d:99:83
由于我的 dhcp 服务器运行在不同的 Linux 服务器中,并且配置为根据 MAC 地址分配一些 IP 地址,因此还请注意,更改对分配的 IP 地址 192.168.111.136 没有影响
/etc/dhcp/dhcpd.conf
作为参考,服务器上基于 MAC 的 IP 地址分配文件的相关条目:
host s19 {
hardware ethernet 3c:7c:3f:0d:99:83;
fixed-address 192.168.111.136;
}
参考(搜索dhcp-identifier
)