温馨提示×

Debian DHCP如何启用中继

小樊
44
2026-08-26 05:57:21
栏目: 智能运维

在 Debian 上启用 DHCP 中继(DHCP Relay / DHCP Helper),通常使用 isc-dhcp-relay(ISC 官方中继)或 dnsmasq(部分场景)。下面以 isc-dhcp-relay 为例,这是最常见、最标准的做法。


一、安装 DHCP 中继软件

sudo apt update
sudo apt install isc-dhcp-relay

安装过程中会弹出配置界面(可用 dpkg-reconfigure isc-dhcp-relay 重新配置)。


二、配置 DHCP 中继

1️⃣ 编辑配置文件

主配置文件:

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:可选高级参数


2️⃣ 常见场景示例

场景:客户端在 VLAN 10,DHCP 服务器在另一网段

SERVERS="10.0.0.5"
INTERFACES="eth1"

三、启动并启用服务

sudo systemctl restart isc-dhcp-relay
sudo systemctl enable isc-dhcp-relay

查看状态:

systemctl status isc-dhcp-relay

四、防火墙与网络注意事项(非常重要)

1️⃣ 允许 DHCP 中继流量

DHCP 中继使用的是:

  • UDP 67(服务器)
  • UDP 68(客户端)

确保防火墙放行:

# nftables / iptables 示例
sudo iptables -A INPUT -p udp --dport 67 -j ACCEPT
sudo iptables -A INPUT -p udp --dport 68 -j ACCEPT

2️⃣ 路由必须可达

中继服务器必须:

  • ping 通 DHCP 服务器
  • 到达客户端网段

否则中继会失败。


五、验证是否工作

1️⃣ 在 DHCP 服务器上抓包

tcpdump -i eth0 port 67 or port 68

应看到来自中继 IP 的 DHCP 请求(GIADDR 字段不为 0)。


2️⃣ 客户端测试

dhclient -v eth0

六、使用 dnsmasq 作为 DHCP 中继(可选)

如果你已经在用 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 中继步骤:

  1. 安装 isc-dhcp-relay
  2. 配置 DHCP 服务器地址和接口
  3. 启动服务
  4. 确保路由 + 防火墙正确
  5. 抓包验证

如果你愿意,可以告诉我:

  • 网络拓扑(VLAN / 多网卡)
  • DHCP 服务器类型(Windows / ISC DHCP / 路由器)
  • Debian 版本(11 / 12)

我可以给你一份 完全贴合你环境的配置示例

0