dhcpcd Documentation

repository·master·Indexed 19 days ago

https://github.com/networkconfiguration/dhcpcd

dhcpcd is a DHCP (v4/v6) and IPv4LL (ZeroConf) client designed to automatically configure network interfaces. This documentation covers daemon configuration via dhcpcd.conf, build instructions using the configure script, binary size reduction options, cross-compilation, and the use of network event hooks.

Tokens
2.2K
Snippets
11
Records
16
Agent score
16%

What's inside dhcpcd

  1. Overview of dhcpcd

    master

    dhcpcd is a DHCP and DHCPv6 client, as well as an IPv4LL (ZeroConf) client. It is designed to run on a machine to silently configure network settings for attached networks with minimal manual configuration.

    For desktop users, dhcpcd-ui (Network Configurator) is available as a notification area application to monitor network state and provide a configuration dialog for wireless networks.

  2. Build dhcpcd using configure

    master

    dhcpcd uses a POSIX shell script ./configure for building, which functions similarly to GNU configure. Note that some build-time warnings are expected on most platforms (except DragonFlyBSD and NetBSD).

    To build, run the configure script followed by your preferred build command (typically make).

    ./configure
  3. Reduce dhcpcd binary size

    master

    If you are building for installation media or environments where disk space is limited, you can reduce the binary size using several options:

    • --small: Enables a reduced feature set (removes non-essential options from dhcpcd-definitions.conf, logfile option, DHCPv6 Prefix Delegation, and IPv6 address announcement).
    • --disable-inet: Removes the IPv4 stack.
    • --disable-inet6: Removes the IPv6 stack.
    • --disable-auth: Removes authentication features.
    • --disable-arp: Removes ARP support.
    • --disable-arping: Removes arping support.
    • --disable-ipv4ll: Removes IPv4 Link Local support.
    • --disable-dhcp6: Removes DHCPv6 support.
    • --disable-privsep: Removes privilege separation.
    • --disable-embedded: Moves the embedded extended configuration from the binary to an external file (LIBEXECDIR/dhcpcd-definitions.conf). Note that if this file cannot be loaded at runtime, dhcpcd will only decode DHCP/DHCPv6 options explicitly defined in /etc/dhcpcd.conf.
    ./configure --small
  4. Import dhcpcd source code

    master

    If you need to import dhcpcd into another source control system, use the make targets:

    • import: Imports the full source tree.
    • import-src: Imports only the necessary source files and documentation.

    Both targets support the DESTDIR variable to specify the installation directory. If unset, it defaults to /tmp/dhcpcd-$VERSION.

    make DESTDIR=/usr/src/contrib/dhcpcd import-src
  5. Upgrade considerations for dhcpcd

    master

    When upgrading dhcpcd, be aware of changes to default directory locations:

    • dhcpcd-7+: The database directory defaults to /var/db/dhcpcd (previously /var/db). Files dhcpcd.duid and dhcpcd.secret are stored here instead of /etc.
    • dhcpcd-9+: The run directory defaults to /var/run/dhcpcd (previously /var/run), and the dhcpcd prefix has been removed from files within that directory.
  6. Cross-compile dhcpcd

    master

    When cross-compiling for a different OS than your host, use the --target flag to specify the target platform.

    For MMU-less systems where fork() is unavailable, use --disable-fork. This automatically enables the --no-background flag and prevents the --background flag from working.

    ./configure --target=sparc-sun-netbsd5.0
    ./configure --disable-fork
  7. Use and add dhcpcd hooks

    master

    Hooks allow dhcpcd to perform actions during network events.

    Default Hooks:

    • 01-test
    • 20-resolv.conf
    • 30-hostname

    Additional Hooks: Some hooks (like 10-wpa_supplicant, 15-timezone, and 29-lookup-hostname) are located in $(datadir)/dhcpcd/hooks and must be manually copied to $(libexecdir)/dhcpcd-hooks to be active.

    Adding Hooks: You can specify a hook to be included during configuration using the -with-hook flag.

    ./configure -with-hook=ntp.conf
  8. Configure SECCOMP and Privilege Separation

    master

    Linux SECCOMP behavior depends on the relationship between libc and the kernel. If a libc update introduces a syscall that dhcpcd's SECCOMP filter does not recognize, dhcpcd may break.

    To resolve this, you can use --disable-seccomp. This allows dhcpcd to still use a POSIX resource-limited sandbox via privilege separation without the SECCOMP filter.

    ./configure --disable-seccomp
  9. Configure dhcpcd via dhcpcd.conf

    master

    Configuration options for the dhcpcd daemon are placed in /etc/dhcpcd.conf. For a complete list of available options, refer to the dhcpcd.conf(5) man page.

    Sample Configuration

    Below is a sample configuration demonstrating common use cases such as hostname reporting, DUID usage, and persistent interface configuration.

    # A sample configuration for dhcpcd.
    # See dhcpcd.conf(5) for details.
    
    # Allow users of this group to interact with dhcpcd via the control socket.
    #controlgroup wheel
    
    # Inform the DHCP server of our hostname for DDNS.
    hostname
    
    # Use the hardware address of the interface for the Client ID.
    #clientid
    # or
    # Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
    # Some non-RFC compliant DHCP servers do not reply with this set.
    # In this case, comment out duid and enable clientid above.
    duid
    
    # Persist interface configuration when dhcpcd exits.
    persistent
    
    # Rapid commit support.
    # Safe to enable by default because it requires the equivalent option set
    # on the server to actually work.
    option rapid_commit
    
    # A list of options to request from the DHCP server.
    option domain_name_servers, domain_name, domain_search, host_name
    option classless_static_routes
    # Respect the network MTU. This is applied to DHCP routes.
    option interface_mtu
    
    # Most distributions have NTP support.
    #option ntp_servers
    
    # A ServerID is required by RFC2131.
    require dhcp_server_identifier
    
    # Generate SLAAC address using the Hardware Address of the interface
    #slaac hwaddr
    # OR generate Stable Private IPv6 Addresses based from the DUID
    slaac private