在 Debian 里,“DHCP 优先级”通常有几种不同含义,需要先区分清楚。下面按最常见场景分别说明,并给出配置示例。
结论:DHCP 协议本身没有“优先级”字段。
客户端通常:
apt install isc-dhcp-relay
# /etc/default/isc-dhcp-relay
SERVERS="192.168.1.10 192.168.2.10"
先写的服务器通常先被转发。
这是 路由优先级(metric)问题,不是 DHCP 本身。
dhclient 设置路由 metric编辑接口配置:
nano /etc/dhcp/dhclient.conf
interface "eth0" {
supersede routers 192.168.1.1;
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
}
但更常见做法是在 网络配置中设置 metric。
auto eth0
iface eth0 inet dhcp
metric 100
auto eth1
iface eth1 inet dhcp
metric 200
✅ metric 越小,优先级越高
查看:
ip route
nmcli connection modify eth0 ipv4-route-metric 100
nmcli connection modify eth1 ipv4-route-metric 200
编辑 DHCP 服务器配置:
nano /etc/dhcp/dhcpd.conf
host server1 {
hardware ethernet 00:11:22:33:44:55;
fixed-address 192.168.1.10;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
option routers 192.168.1.1;
}
class "high-priority" {
match if substring(hardware, 1, 3) = 00:11:22;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
pool {
range 192.168.1.10 192.168.1.50;
allow members of "high-priority";
}
pool {
range 192.168.1.100 192.168.1.200;
}
}
DHCP 可以指定:
option domain-name-servers 8.8.8.8, 114.114.114.114;
option routers 192.168.1.1;
客户端一般:
| 需求 | 正确做法 |
|---|---|
| 多个 DHCP 服务器选谁 | 控制响应速度 / relay 顺序 |
| 多网卡 DHCP 路由优先 | 设置 metric |
| 给某些设备优先 IP | MAC / class / pool |
| 控制 DNS / 网关 | DHCP 选项 |
| 协议级 DHCP 优先级 | ❌ 不存在 |
如果你能具体说明是 客户端 / 服务器 / 多网卡 / 多 DHCP 服务器 / PXE / 企业网络,我可以给你精确到命令级别的配置方案。