温馨提示×

debian dhcp怎样加子网

小樊
35
2026-10-25 10:12:35
栏目: 智能运维

在 Debian 上配置 DHCP 服务并“加子网”,通常是指 在 DHCP 服务器(如 isc-dhcp-server)中新增一个作用域(subnet),或者给已有网络再划分/增加一个子网。下面分情况说明。


一、使用 ISC DHCP Server(最常见)

1. 安装 DHCP 服务

sudo apt update
sudo apt install isc-dhcp-server

2. 编辑 DHCP 配置文件

配置文件一般是:

/etc/dhcp/dhcpd.conf

3. 添加一个子网(示例)

假设你要增加一个 192.168.10.0/24 的子网:

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 domain-name-servers 8.8.8.8, 8.8.4.4;
  default-lease-time 600;
  max-lease-time 7200;
}

4. 指定 DHCP 监听的网卡(重要)

编辑:

/etc/default/isc-dhcp-server

例如:

INTERFACESv4="eth0"

⚠️ DHCP 服务器必须有一个 IP 在你要服务的子网里,否则不会生效。

5. 重启服务

sudo systemctl restart isc-dhcp-server

二、一台 DHCP 服务器服务多个子网(跨子网)

如果 DHCP 服务器和客户端不在同一个子网,需要:

方案 1:在路由器上配置 DHCP Relay

apt install isc-dhcp-relay

配置:

/etc/default/isc-dhcp-relay

示例:

SERVERS="192.168.1.10"
INTERFACES="eth0"

方案 2:DHCP 服务器有多张网卡,每张网卡一个子网


三、只是“给网卡加一个子网 IP”(不是 DHCP)

如果你是在 Debian 上给网卡加第二个子网 IP(例如加 192.168.20.0/24):

Debian 11/12(使用 systemd-networkd 或 /etc/network/interfaces)

使用 /etc/network/interfaces

auto eth0
iface eth0 inet static
  address 192.168.1.10/24

iface eth0 inet static
  address 192.168.20.10/24

然后:

sudo systemctl restart networking

四、常见错误排查

  • DHCP 不分配 IP:
    • 服务器 IP 不在 subnet 内
    • 网卡未写在 INTERFACESv4
    • 防火墙阻断 UDP 67/68
  • 查看日志:
journalctl -u isc-dhcp-server

如果你能具体说明:

  • 是 DHCP 加子网 还是 Linux 网卡加子网
  • Debian 版本
  • 网络拓扑(单网卡 / 多网卡 / 跨网段)

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

0 踩