dhcpcd-10.3.0

Introduction to dhcpcd

dhcpcd is an implementation of the DHCP client specified in RFC2131. A DHCP client is useful for connecting your computer to a network which uses DHCP to assign network addresses. dhcpcd strives to be a fully featured, yet very lightweight DHCP client.

[Note]

Note

Development versions of BLFS may not build or run some packages properly if LFS or dependencies have been updated since the most recent stable versions of the books.

Package Information

dhcpcd Dependencies

Optional

LLVM-21.1.8 (with Clang), ntp-4.2.8p18, chronyd, and ypbind

Privilege separation

Recent releases of dhcpcd optionally support privilege separation. As the practical security benefits of this are unclear for a program like dhcpcd and the setup is more complicated, the book currently defaults to disable it.

If you however would like to use privilege separation, additional installation steps are necessary to set up the proper environment. Issue the following commands as the root user:

install  -v -m700 -d /var/lib/dhcpcd &&

groupadd -g 52 dhcpcd        &&
useradd  -c 'dhcpcd PrivSep' \
         -d /var/lib/dhcpcd  \
         -g dhcpcd           \
         -s /bin/false       \
         -u 52 dhcpcd &&
chown    -v dhcpcd:dhcpcd /var/lib/dhcpcd 

Installation of dhcpcd

Build dhcpcd without privilege separation by running the following command:

./configure --prefix=/usr                \
            --sysconfdir=/etc            \
            --libexecdir=/usr/lib/dhcpcd \
            --dbdir=/var/lib/dhcpcd      \
            --runstatedir=/run           \
            --disable-privsep         &&
make

Alternatively, build dhcpcd with privilege separation by running the following commands:

./configure --prefix=/usr                \
            --sysconfdir=/etc            \
            --libexecdir=/usr/lib/dhcpcd \
            --dbdir=/var/lib/dhcpcd      \
            --runstatedir=/run           \
            --privsepuser=dhcpcd         &&
make

To test the results, issue: make test.

Now, as the root user:

make install

Command Explanations

--libexecdir=/usr/lib/dhcpcd: This switch sets a better location for the dhcpcd internal libraries.

--dbdir=/var/lib/dhcpcd: This switch adjusts the database directory because the default directory, /var/db, is not FHS-compliant.

--runstatedir=/run: This switch sets the runtime state directory because the default /var/run is a symbolic link to /run, and using /var/run is deprecated.

--disable-privsep: This switch disables privilege separation, which is the default in dhcpcd. This switch is not used in the build configuration where privilege separation is used.

--privsepuser=dhcpcd: This switch sets the privilege separation user in the build configuration where privilege escalation is used.

--with-hook=...: You can optionally install more hooks, for example to install some configuration files such as ntp.conf. A set of hooks can be found in the dhcpcd-hooks directory in the build tree.

Configuring dhcpcd

Config Files

/etc/dhcpcd.conf

General Configuration Information

To configure dhcpcd, you need to first install the OpenRC service for it, then make a few edits to it as the root user:

install -vDm755 /dev/stdin /etc/init.d/dhcpcd << "EOF" &&
#!/sbin/openrc-run
# Starts the dhcpcd daemon.
# Authors: Zeckma - zeckma.tech@gmail.com
# Version: LFS 12.5

description="starts dhcpcd"

command=/sbin/dhcpcd
pidfile=/var/run/dhcpcd.pid
command_args="-B -q ${dhcpcd_options} ${iface}"
command_background=yes

depend() {
  provide net
  need localmount
  use logger
  after bootmisc modules
  before dns
}
EOF

rc-update add dhcpcd default
[Note]

Note

The default for dhcpcd is to set the hostname and mtu. It also overwrites /etc/resolv.conf and /etc/ntp.conf. These modifications to system files are done by hooks which are stored in /usr/lib/dhcpcd/dhcpcd-hooks. You can change this behavior by removing or adding hooks from/to that directory. The execution of hooks can be disabled by using the --nohook (-C) command line option or by the nohook option in the /etc/dhcpcd.conf file.

The service needs a corrosponding configuration file made for it. Create one now as the root user:

cat > /etc/conf.d/dhcpcd << "EOF"
iface="<interface>"
dhcpcd_options=""
EOF

Replace <interface> with the interface you want to run dhcpcd on. This could be eth0, wlo1, or something else. Run ip addr for a full list of interfaces. If an interface you want isn't available, it may be because the interface needs kernel drivers built for it or the drivers tried to load firmware that was not built into the kernel or wasn't present on the system at boot time.

Configuration Information: fixed ip

Although not usual, it is possible that you need to configure dhcpcd to use a fixed ip. Here, we give an example. As the root user, add to the /etc/dhcpcd.conf configuration file using the following commands. Adjust appropriately for additional interfaces and for the actual ip and router you need:

cat >> /etc/dhcpcd.conf << "EOF"
static ip_address=192.168.0.10/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
EOF

You can either use DNS servers in /etc/resolv.conf from another system, your preferred servers, or just the example /etc/resolv.conf.head file below as is:

cat > /etc/resolv.conf.head << "EOF"
# OpenDNS servers
nameserver 208.67.222.222
nameserver 208.67.220.220
EOF

Contents

Installed Program: dhcpcd
Installed Library: /usr/lib/dhcpcd/dev/udev.so
Installed Directory: /{usr,var}/lib/dhcpcd and /usr/share/dhcpcd

Short Descriptions

dhcpcd

is an implementation of the DHCP client specified in RFC2131

udev.so

adds udev support for interface arrival and departure; this is because udev likes to rename the interface, which it can't do if dhcpcd grabs it first