温馨提示×

debian dhcp怎么配多网段

小樊
47
2026-09-23 03:57:14
栏目: 智能运维

在 Debian 上通过 ISC DHCP Server(isc-dhcp-server) 配置多网段(多子网),主要有两种常见场景:


一、单网卡绑定多个 IP(单臂 / 多子网)

1. 配置网卡多 IP

编辑 /etc/network/interfaces(或用 netplan,如果你用的是新版本)

auto eth0
iface eth0 inet static
    address 192.168.1.1
    netmask 255.255.255.0

auto eth0:1
iface eth0:1 inet static
    address 192.168.2.1
    netmask 255.255.255.0

重启网络:

systemctl restart networking

2. 配置 DHCP 多子网

编辑 /etc/dhcp/dhcpd.conf

subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.100 192.168.1.200;
    option routers 192.168.1.1;
    option domain-name-servers 8.8.8.8;
}

subnet 192.168.2.0 netmask 255.255.255.0 {
    range 192.168.2.100 192.168.2.200;
    option routers 192.168.2.1;
    option domain-name-servers 8.8.8.8;
}

3. 指定 DHCP 监听网卡

编辑 /etc/default/isc-dhcp-server

INTERFACESv4="eth0"

启动服务:

systemctl restart isc-dhcp-server

✅ 适合:单臂路由 / 交换机 VLAN 共用口


二、多网卡对应多网段(推荐)

1. 配置多网卡 IP

auto eth0
iface eth0 inet static
    address 192.168.1.1
    netmask 255.255.255.0

auto eth1
iface eth1 inet static
    address 10.0.0.1
    netmask 255.255.255.0

2. DHCP 配置

subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.100 192.168.1.200;
    option routers 192.168.1.1;
}

subnet 10.0.0.0 netmask 255.255.255.0 {
    range 10.0.0.100 10.0.0.200;
    option routers 10.0.0.1;
}

3. 监听多个网卡

INTERFACESv4="eth0 eth1"
systemctl restart isc-dhcp-server

✅ 适合:物理隔离网络


三、VLAN + 多网段(进阶)

如果网段是通过 VLAN 划分的:

  1. 创建 VLAN 子接口
ip link add link eth0 name eth0.10 type vlan id 10
ip addr add 192.168.10.1/24 dev eth0.10
ip link set eth0.10 up
  1. DHCP 监听 eth0.10
  2. dhcpd.conf 中配置对应 subnet

四、常见问题排查

journalctl -u isc-dhcp-server
cat /var/lib/dhcp/dhcpd.leases

常见错误:

  • subnet 没有对应网卡 IP
  • 防火墙拦截 UDP 67/68
  • 配置文件语法错误

如果你能说明:

  • Debian 版本
  • 是否用 VLAN
  • 单网卡还是多网卡

我可以给你更精确的配置示例。

0 踩