dhcpcd 是 DHCP 和 DHCPv6 客户端，是目前功能最丰富的开源 DHCP 客户端。项目主页包含了完整的功能列表。
安装 软件包 包.
要为 全部 网络接口提供服务，start/enable
建议使用模板单元方式，不管是那种方式，都会分配一个动态 IP 地址。要分配静态IP地址，请阅读静态配置部分。
/etc/dhcpcd.exit-hook. 下面的例子中添加了一个 VPN 子网
ip route add 10.11.12.0/24 via 192.168.192.5
服务器可以通过下列方式不同的 DHCP 客户端：
- 主机名 (或客户端发送的主机名),
- 所用网卡的 MAC 地址，
- Identity Association ID (身份关联ID IAID)，区分不同使用场景或接口的标识，
- DHCP 唯一标识 (DUID).
详情请参考 RFC 3315.
DHCP 服务器通过配置决定申请 DHCP ID 租约时，哪些是必须的，哪些是可选的。
如果无法通过 dhcpcd 默认配置获取 IP 地址，可以在
clientid发送 MAC 地址作为标识
iaid <interface>生成并发送 IAID,可以在接口块(
interface <interface>)中使用，参考： )，下面的选项更常用：
duid将联合使用 DUID 和 IAID 作为标识.
/var/lib/dhcpcd/duid 中，为了保证 DHCP 租约的有效性，需要保证 DUID 在整个网络中是唯一的，而 IAID 需要能区分每一个接口(RFC 4361).
如果运行的是 动态 DNS，请确保三个都是唯一的。如果网络中出现重复的 DUID,例如克隆的虚拟机中，有不同的主机名和 MAC 地址，但是没有修改 DUID 时，最新获取IP地址的客户端会清除之前 DUID 获取的地址。
/etc/dhcpcd.conf 中为 dhcpcd 配置静态地址：
interface eth0 static ip_address=192.168.0.10/24 static routers=192.168.0.1 static domain_name_servers=192.168.0.1 22.214.171.124
arping 选项，详情请参考 。
可以为 dhcpcd 添加备用设置，当 DHCP 续租失败时使用，在 无显示设备机器 特别有用，动态地址无法获取时，使用静态地址作为备用，确保机器有可用的网络连接。
# define static profile profile static_eth0 static ip_address=192.168.1.23/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1 # fallback to static profile on eth0 interface eth0 fallback static_eth0
/usr/lib/dhcpcd/dhcpcd-hooks/ 中配置的钩子，详情请参考 和 。
Enable this hook by creating a symbolic link, which ensures the current version is used, even after package updates:
# ln -s /usr/share/dhcpcd/hooks/10-wpa_supplicant /usr/lib/dhcpcd/dhcpcd-hooks/
10-wpa_supplicant hook, if enabled, automatically launches wpa_supplicant on wireless interfaces. It is started only if:
- no wpa_supplicant process is already listening on that interface.
- a wpa_supplicant configuration file exists. dhcpcd checks
/etc/wpa_supplicant/wpa_supplicant-interface.conf /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant-interface.conf /etc/wpa_supplicant.conf
by default, in that order, but a custom path can be set by adding
env wpa_supplicant_conf=configuration_file_path into
If you manage wireless connections with wpa_supplicant itself, the hook may create unwanted connection events. For example, if you stop wpa_supplicant the hook may bring the interface up again. Also, if you use netctl-auto, wpa_supplicant is started automatically with
/run/network/wpa_supplicant_interface.conf for config, so starting it again from the hook is unnecessary and may result in boot-time parse errors of the
/etc/wpa_supplicant/wpa_supplicant.conf file, which only contains dummy values in the default packaged version.
To disable the hook remove the symbolic link you added, or add
nohook wpa_supplicant to
dhcpcd contains an implementation of a recommendation of the DHCP standard (RFC 2131) to verify via ARP if the assigned IP is not used by something else. This is usually not needed in home networks, so it is possible to save about 5 seconds on every connect by disabling it:
This is equivalent to passing
dhcpcd, and disables the described ARP probing, speeding up connections to networks with DHCP.
interface is the name of the interface on which you have a lease, contains the actual DHCP lease reply sent by the DHCP server. For a wireless interface, the filename is
ssid is the name of the wireless network. It is used to determine the last lease from the server, and its
mtime attribute is used to determine when it was issued. This last lease information is then used to request the same IP address previously held on a network, if it is available. If you do not want that, simply delete this file.
If the DHCP server still assigns the same IP address, this may happen because it is configured to keep the assignment stable and recognizes the requesting DHCP client id or DUID (see #DHCP Client Identifier). You can test it by stopping dhcpcd and removing or renaming
/var/lib/dhcpcd/duid. dhcpcd will generate a new one on next run.
Keep in mind that the DUID is intended as persistent machine identifier across reboots and interfaces. If you are transferring the system to new computer, preserving this file should make it appear as old one.
If you are dualbooting Arch and macOS or Windows and want each to receive different IP addresses, you can exert control about the IPs leased by specifying a different DUID in each operating system installation.
In Windows the DUID should be stored in the
On macOS it is directly accessible in
Network\adapter\dhcp preferences panel.
If you are using a dnsmasq DHCP server, the different DUIDs can be used in appropriate
dhcp-host= rules in its configuration.
If resolvconf is available DNS information will be sent to it, if not, then dhcpcd itself will write to
/etc/resolv.conf overwriting can be stopped by disabling the hook
/usr/lib/dhcpcd/dhcpcd-hooks/20-resolv.conf. Do so by adding the following to the last section of
Alternatively, you can create a file called
/etc/resolv.conf.head containing your DNS servers. dhcpcd will prepend this file to the beginning of
Or you can configure dhcpcd to use the same DNS servers every time. To do this, add the following line at the end of your
dns-server-ip-addressses is a space separated list of DNS IP addresses.
For example, to set it to Google's DNS servers:
static domain_name_servers=126.96.36.199 188.8.131.52
/etc/resolvconf.conf. This way they will not get overwritten by any resolvconf supporting software.
If you are on a network with DHCPv4 that filters Client IDs based on MAC addresses, you may need to change the following line:
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 Client ID as per RFC4361. duid
# Use the hardware address of the interface for the Client ID (DHCPv4). clientid
A problem may occur when DHCP gets a wrong IP assignment, such as when two routers are tied together through a VPN. The router that is connected through the VPN may be assigning IP address. To fix it, as root, release the IP address:
# dhcpcd -k
Then request a new one:
You may have to run those two commands many times.
For some (noncompliant) routers, you will not be able to connect properly unless you comment the line
/etc/dhcpcd.conf. This should not cause issues unless you have multiple DHCP servers on your network (not typical); see this page for more information.
dhcpcd.service can be enabled without specifying an interface. This may, however, create a race condition at boot with systemd-udevd trying to apply a predictable network interface name:
error changing net interface name wlan0 to wlp4s0: Device or resource busy"
To avoid it, enable dhcpcd per interface it should bind to as described in #Running. The downside of the template unit is, however, that it does not support hot-plugging of a wired connection and will fail if the network cable is not connected. To work-around the failure, see #Timeout delay.
It is also possible to use
allowinterfaces in to stop dhcpcd from binding to kernel names, for example
denyinterfaces wlan* eth*
If dhcpcd operates on a single interface and fails to obtain a lease after 30 seconds (for example when the server is not ready or the cable not plugged), it will exit with an error.
To have dhcpcd wait indefinitely for one-time, edit the unit and set the
timeout option to
[Service] ExecStart= ExecStart=/usr/bin/dhcpcd -w -q -t 0 %I
To have it wait indefinitely, let the unit restart after it exited:
dhcpcd@.service 会在获取 IP 地址后进入守护进程(dhcpcd
-w )。启用单元后，会等待 IP 地址的分配，影响启动速度，要修正这个问题，请创建 下面的 drop-in file:
[Service] ExecStart= ExecStart=/usr/bin/dhcpcd -b -q %I
See also FS#49685.