温馨提示×

debian dhcp怎么做中继

小樊
42
2026-09-23 03:50:13
栏目: 智能运维

在 Debian 上配置 DHCP 中继(DHCP Relay / dhcrelay),通常使用 isc-dhcp-relay 或 kea-dhcp-relay。下面以 ISC DHCP Relay(最常见) 为例说明。


一、安装 DHCP 中继

sudo apt update
sudo apt install isc-dhcp-relay

安装过程中会提示输入:

  • DHCP 服务器地址
  • 监听网卡

也可以安装后手动改配置文件。


二、配置 DHCP 中继

配置文件:

/etc/default/isc-dhcp-relay

示例配置:

# DHCP 服务器地址(可多个,空格分隔)
SERVERS="192.168.10.1"

# 中继监听的网卡
INTERFACES="eth0 eth1"

# 可选:中继自身 IP(通常不用写)
OPTIONS=""

含义说明:

  • SERVERS:真正的 DHCP Server IP
  • INTERFACES:客户端所在的网卡(不是 DHCP Server 网卡)

三、开启 IP 转发(必须)

DHCP 中继依赖 Linux 路由功能:

sudo sysctl -w net.ipv4.ip_forward=1

永久生效:

echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

四、启动 DHCP 中继

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

查看状态:

systemctl status isc-dhcp-relay

五、防火墙注意

如果启用了 iptables / nftables / ufw,需要放行:

  • UDP 67(DHCP Server)
  • UDP 68(DHCP Client)

例如:

sudo ufw allow 67/udp
sudo ufw allow 68/udp

六、典型拓扑示例

Client --- eth0 (中继) eth1 --- DHCP Server
  • 中继机:
    • eth0:192.168.1.1(客户端网段)
    • eth1:192.168.10.2
  • DHCP Server:192.168.10.1

中继配置:

SERVERS="192.168.10.1"
INTERFACES="eth0"

七、常见问题

1. 客户端收不到 IP

  • 没开 ip_forward
  • 防火墙阻挡 UDP 67/68
  • DHCP Server 未配置对应网段/中继地址

2. DHCP Server 上看不到请求

  • 中继 INTERFACES 写错
  • 路由不通

3. 多 DHCP Server

SERVERS="192.168.10.1 192.168.10.2"

如果你用的是 KEA DHCP 或 网络交换机 DHCP Relay + Debian Server,可以告诉我,我可以给对应方案。

0 踩