Ubuntu 配置 DHCP 中继代理
一 方案总览与准备
二 使用 isc-dhcp-relay 的标准做法(推荐)
sudo apt update && sudo apt install isc-dhcp-relayINTERFACESv4="eth0 eth1"(填写连接客户端网段的接口)RELAY_ADDRESS="192.168.1.100"(上游 DHCP 服务器 IP)RELAY_PORT=67(服务器端口,默认 67)RELAY_OPTIONS="option 6,192.168.1.1;option 12,8.8.8.8,8.8.4.4"(为客户端下发默认网关与 DNS)sudo systemctl start isc-dhcp-relay && sudo systemctl enable isc-dhcp-relaysudo ufw allow 67/udp 与 sudo ufw allow 68/udpsudo firewall-cmd --permanent --add-service=dhcp && sudo firewall-cmd --reloadsudo systemctl status isc-dhcp-relaysudo tail -f /var/log/syslog | grep isc-dhcp-relaysudo tcpdump -i eth0 port 67 or port 68三 使用 dnsmasq 的做法(轻量一体化)
sudo apt update && sudo apt install dnsmasqinterface=eth0(仅在中继接口监听 DHCP)dhcp-range=192.168.10.100,192.168.10.200,12h(仅为该网段下发地址;若服务器在该接口网段,可保留此行;跨网段中继时以服务器为准)relay=192.168.1.100#67(上游 DHCP 服务器 IP 与端口)sudo systemctl restart dnsmasqsudo systemctl status dnsmasqsudo tcpdump -i eth0 port 67 or port 68四 常见问题与排查要点
RELAY_ADDRESS 或 relay= 中指定 多个 DHCP 服务器 IP,提升可靠性。