在 Debian 上启用 DHCP 中继(DHCP Relay / DHCP Helper),通常使用 isc-dhcp-relay(ISC 官方中继)或 dnsmasq(部分场景)。下面以 isc-dhcp-relay 为例,这是最常见、最标准的做法。
sudo apt update
sudo apt install isc-dhcp-relay
安装过程中会弹出配置界面(可用 dpkg-reconfigure isc-dhcp-relay 重新配置)。
主配置文件:
sudo nano /etc/default/isc-dhcp-relay
典型配置示例:
# DHCP 服务器地址(可以是多个,用空格分隔)
SERVERS="192.168.10.1"
# 监听的接口(客户端所在网段)
INTERFACES="eth0"
# 可选:指定源地址(用于多网卡或策略路由)
# OPTIONS="-a 192.168.1.1"
✅ SERVERS:真正的 DHCP 服务器 IP
✅ INTERFACES:接收 DHCP 请求的接口
✅ OPTIONS:可选高级参数
SERVERS="10.0.0.5"
INTERFACES="eth1"
sudo systemctl restart isc-dhcp-relay
sudo systemctl enable isc-dhcp-relay
查看状态:
systemctl status isc-dhcp-relay
DHCP 中继使用的是:
确保防火墙放行:
# nftables / iptables 示例
sudo iptables -A INPUT -p udp --dport 67 -j ACCEPT
sudo iptables -A INPUT -p udp --dport 68 -j ACCEPT
中继服务器必须:
否则中继会失败。
tcpdump -i eth0 port 67 or port 68
应看到来自中继 IP 的 DHCP 请求(GIADDR 字段不为 0)。
dhclient -v eth0
如果你已经在用 dnsmasq,也可以启用中继模式:
# /etc/dnsmasq.conf
dhcp-relay=192.168.1.1,192.168.10.1,eth0
但 isc-dhcp-relay 更稳定、更适合企业环境。
| 问题 | 原因 |
|---|---|
| 客户端拿不到 IP | 路由不通 / 防火墙拦截 |
| DHCP 服务器收不到请求 | 中继接口配置错误 |
| 只能中继部分 VLAN | 接口未包含 / VLAN 未透传 |
| 日志无信息 | 查看 /var/log/syslog |
✅ Debian 启用 DHCP 中继步骤:
isc-dhcp-relay如果你愿意,可以告诉我:
我可以给你一份 完全贴合你环境的配置示例。