LinuxCommandLibrary

dhcpcd

Obtain IP address from DHCP server

TLDR

Release all address leases

$ sudo dhcpcd [[-k|--release]]
copy

Request the DHCP server for new leases
$ sudo dhcpcd [[-n|--rebind]]
copy

SYNOPSIS

dhcpcd [OPTIONS] [INTERFACE...]

PARAMETERS

-b, --background
    Background the client after configuration.

-d, --debug
    Enable verbose debug messages.

-k, --release
    Release the IP address and exit. Removes lease information.

-n, --rebind
    Force a rebind to a new lease.

-r, --request
    Request a specific IP address from the DHCP server.

-x, --exit
    Exit and remove the lease. Similar to -k but also removes dynamic routes and DNS entries.

-w, --waitip
    Wait for an IP address to be configured before exiting. Useful in scripts.

-c, --config
    Specify an alternative configuration file path instead of the default /etc/dhcpcd.conf.

-4, --ipv4only
    Only configure IPv4 addresses; ignore IPv6.

-6, --ipv6only
    Only configure IPv6 addresses (DHCPv6 and SLAAC); ignore IPv4.

DESCRIPTION

dhcpcd is a DHCP client daemon that automatically configures network interfaces on Linux systems. It supports both IPv4 and IPv6 (including DHCPv6 and SLAAC) and manages the entire network configuration lifecycle: discovering DHCP servers, requesting an IP address, configuring the interface (IP, netmask, gateway, DNS servers), and renewing leases.

Known for its robustness and efficiency, dhcpcd can handle multiple network interfaces simultaneously, manage static IP configurations, and ensure persistent network settings across reboots. It interacts with the kernel to set up routes and DNS resolution. Its extensible hook system allows for custom scripts to be executed at various stages of the DHCP process, making it highly customizable for diverse networking environments. It's a foundational tool for automated network setup, especially in environments where network configuration needs to be dynamic and reliable.

CAVEATS

dhcpcd typically requires root privileges to operate as it modifies network interfaces and system configuration files. It can potentially conflict with other network management services (e.g., NetworkManager, systemd-networkd) if they are simultaneously attempting to configure the same network interface. Proper configuration, especially via /etc/dhcpcd.conf, is crucial to avoid network misconfigurations and ensure desired behavior.

CONFIGURATION FILE

The primary configuration file for dhcpcd is /etc/dhcpcd.conf. This file allows users to define static IP addresses, specify desired options to send/request from the DHCP server, set timeouts, manage persistent leases, and control other advanced network settings. It's critical for persistent and customized network behavior, overriding default command-line options.

HOOKS

dhcpcd uses an extensive hook system, with scripts typically located in /usr/lib/dhcpcd/dhcpcd-hooks/ (or similar distribution-specific paths). These scripts are executed at different stages of the DHCP process (e.g., when an IP is obtained, renewed, or released). They are responsible for vital tasks like updating /etc/resolv.conf with DNS server information, configuring NTP servers, or running custom post-configuration actions.

HISTORY

dhcpcd originated from NetBSD and has been ported to Linux, becoming a popular choice for its lightweight footprint and robust performance. It's widely adopted in various Linux distributions and embedded systems due to its reliability in managing dynamic network configurations. Its continuous development has ensured support for modern network protocols, including DHCPv6 and Stateless Address Autoconfiguration (SLAAC), maintaining its relevance as a core network configuration tool.

SEE ALSO

dhclient(8), ip(8), resolvconf(8), systemd-networkd(8), ifconfig(8)

Copied to clipboard