在 Ubuntu 上配置 DHCP 中继代理(DHCP Relay / DHCP Helper),通常使用 ISC DHCP Relay(isc-dhcp-relay) 或 systemd 的 dhcrelay。下面按常见场景说明。
sudo apt update
sudo apt install isc-dhcp-relay
安装过程中会提示输入:
也可以安装后手动修改配置文件。
编辑配置文件:
sudo nano /etc/default/isc-dhcp-relay
示例内容:
# DHCP 服务器地址
SERVERS="192.168.10.10"
# 本地监听接口
INTERFACES="eth0 eth1"
# 其他选项(可选)
OPTIONS=""
说明:
SERVERS:DHCP Server 的 IPINTERFACES:客户端所在网段的接口保存后重启服务:
sudo systemctl restart isc-dhcp-relay
sudo systemctl enable isc-dhcp-relay
sudo dhcrelay -i eth0 -i eth1 192.168.10.10
参数说明:
-i:指定接口⚠️ 此方式重启后失效,仅适合测试。
DHCP 中继使用:
确保防火墙允许:
sudo ufw allow 67/udp
sudo ufw allow 68/udp
sudo sysctl -w net.ipv4.ip_forward=1
永久生效:
sudo nano /etc/sysctl.conf
添加或修改:
net.ipv4.ip_forward=1
在 DHCP Server 上需有对应子网:
subnet 192.168.20.0 netmask 255.255.255.0 {
range 192.168.20.100 192.168.20.200;
option routers 192.168.20.1;
option subnet-mask 255.255.255.0;
}
其中:
192.168.20.0 是客户端网段giaddr# 查看中继状态
systemctl status isc-dhcp-relay
# 抓包检查
sudo tcpdump -i eth0 udp port 67 or udp port 68
如果你能提供:
我可以给你更精确的配置示例。