dhcpd (简体中文)

From ArchWiki

翻译状态:本文是 Dhcpd翻译。上次翻译日期:2017-04-14。如果英文版本有所更改,则您可以帮助同步翻译。


附注: 初创页面(在 Talk:Dhcpd (简体中文)# 中讨论)

dhcpd 是 Internet Systems Consortium DHCP 的服务,它被用作局域网环境中的路由管理。

注意: dhcpd (DHCP (server) daemon) 不是 dhcpcd (DHCP client daemon).


安装 dhcp 包,其位于official repositories


dhcpd 包括一个dhcpd4.service的单元文件, 可用于创建守护进程. It starts the daemon for all network interfaces. 可查看 #只侦听单一网口 了解单一网口配置。


Assign a static IPv4 address to the interface you want to use (in our examples we will use eth0). The first 3 bytes of this address cannot be exactly the same as those of another interface.

# ip link set up dev eth0
# ip addr add dev eth0 # arbitrary address
提示: 通常有三个预留的网段用于私有网络,它们不会与任何互联网中的主机发生冲突:
  • 192.168/16 (subnet, netmask
  • 172.16/12 (subnet, netmask
  • 10/8 (for large networks; subnet, netmask
查阅 RFC 1918.

要在引导时分配静态IP地址,查看 Network configuration#Static IP address

默认的dhcpd.conf 文件包含许多注释的例子,复制一份该文件:

# mv /etc/dhcpd.conf /etc/dhcpd.conf.example


option domain-name-servers,;
option subnet-mask;
option routers;
subnet netmask {


option domain-name-servers,;
option subnet-mask;
option routers;
subnet netmask {

  host macbookpro{
   hardware ethernet 70:56:81:22:33:44;

domain-name-servers 选项包含提供给客户的DNS服务器地址,这个例子中使用了谷歌公共DNS服务器。如果你知道一个本地的DNS服务器 (例如服务商提供的),那么你应该使用这个更DNS。如果DNS服务器部署在本地设备上,应该使用子网络中的地址(如 )。

subnet-mask and routers defines a subnet mask and a list of available routers on the subnet. In most cases for small networks you can use as a mask and specify an IP address of the machine on which you are configuring DHCP server as a router.

subnet blocks defines options for separate subnets, which are mapped to the network interfaces on which dhcpd is running. In our example this is one subnet for single interface eth0, for which we defined the range of available IP addresses. Addresses from this range will be assigned to the connecting clients.



配置 dhcpd

In order to exclude an interface, you must create an empty declaration for the subnet that will be configured on that interface.

This is done by editing the configuration file (for example):

# No DHCP service in DMZ network (
subnet netmask {


There is no service files provided by default to use dhcpd only on one interface so you need to create one:

Description=IPv4 DHCP server on %I

ExecStart=/usr/bin/dhcpd -4 -q -pf /run/dhcpd4.pid %I


This is a template unit, which binds it to a particular interface, for example dhcpd4@eth0.service where eth0 is an interface shown with ip link.

用于 PXE

PXE Configuration is done with the following two options:

filename "/pxelinux.0";

This section can either be in an entire subnet or just in a host definition. next-server is the IP of the TFTP Server, and filename is the filename of the image to boot. For more information see PXE.