在 Debian 上通过 ISC DHCP Server(isc-dhcp-server) 配置多网段(多子网),核心思路是:
subnet 声明下面分步说明。
sudo apt update
sudo apt install isc-dhcp-server
假设:
| 网段 | 网卡 | 网段地址 | 网关 | 地址池 |
|---|---|---|---|---|
| VLAN10 | eth0 | 192.168.10.0/24 | 192.168.10.1 | 192.168.10.100-200 |
| VLAN20 | eth1 | 192.168.20.0/24 | 192.168.20.1 | 192.168.20.100-200 |
# /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.10.1
netmask 255.255.255.0
auto eth1
iface eth1 inet static
address 192.168.20.1
netmask 255.255.255.0
(若用 Netplan,请对应修改)
# /etc/default/isc-dhcp-server
INTERFACESv4="eth0 eth1"
编辑主配置文件:
sudo nano /etc/dhcp/dhcpd.conf
option domain-name "example.local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
default-lease-time 600;
max-lease-time 7200;
# 网段 1
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.100 192.168.10.200;
option routers 192.168.10.1;
option subnet-mask 255.255.255.0;
}
# 网段 2
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;
}
✅ 关键点:
subnet 必须对应服务器在该网段的 IP如果只有一块网卡:
ip link add link eth0 name eth0.10 type vlan id 10
ip link add link eth0 name eth0.20 type vlan id 20
配置 IP 后,在 INTERFACESv4 中写:
INTERFACESv4="eth0.10 eth0.20"
host pc1 {
hardware ethernet 00:11:22:33:44:55;
fixed-address 192.168.10.50;
}
sudo systemctl restart isc-dhcp-server
sudo systemctl status isc-dhcp-server
查看日志:
journalctl -u isc-dhcp-server
cat /var/log/syslog | grep dhcpd
❌ Address range ... not on network
→ 地址池不在 subnet 内
❌ No subnet declaration for eth1
→ 网卡无对应 subnet
❌ 客户端拿不到 IP
→ 检查防火墙 / 交换机 VLAN / 网卡 UP
如果你用的是 Kea DHCP 或 Debian 12+,或者想做 DHCP 中继,我也可以继续讲。