温馨提示×

debian dhcp怎么配置

小樊
48
2026-09-20 03:56:01
栏目: 智能运维

在 Debian 上配置 DHCP,通常有两种场景:

  1. Debian 作为 DHCP 客户端(自动获取 IP)
  2. Debian 作为 DHCP 服务器(提供 IP 给其他设备)

下面分别说明。


一、Debian 作为 DHCP 客户端

1. 使用 /etc/network/interfaces(传统方式)

auto eth0
iface eth0 inet dhcp

然后重启网络:

systemctl restart networking

2. 使用 netplan(Debian 12+ 常见)

编辑 /etc/netplan/01-netcfg.yaml:

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true

应用配置:

netplan apply

二、Debian 作为 DHCP 服务器(isc-dhcp-server)

1. 安装 DHCP 服务

apt update
apt install isc-dhcp-server

2. 配置监听网卡

编辑:

/etc/default/isc-dhcp-server

设置:

INTERFACESv4="eth0"

3. 配置 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, 8.8.4.4;
  default-lease-time 600;
  max-lease-time 7200;
}

4. 启动服务

systemctl enable isc-dhcp-server
systemctl start isc-dhcp-server

5. 查看状态

systemctl status isc-dhcp-server
journalctl -u isc-dhcp-server

三、常见注意事项

  • 服务器必须有静态 IP
  • 防火墙不要阻断 UDP 67/68
  • 一个网络里只能有一个 DHCP 服务器

如果你是想:

  • 在 Debian 12 上配置
  • 用 dnsmasq
  • 做 PXE / 网络启动
  • 配置 固定 IP(MAC 绑定)

可以告诉我你的具体需求。

0 踩