Bring a Linux Interface Online with dhcpcd
A laptop that will not get an address is usually a dhcpcd problem, not a router problem. This guide uses dhcpcd to request a DHCP address on one Linux interface, inspect the result, and make one controlled configuration change. The examples target dhcpcd 10.0.6 from the Debian package dhcpcd-base. Allow 10 to 15 minutes for a normal test. You need a root-capable account, a named network interface, and a DHCP server on the attached network.
The route
Jump straight to the step you need, or tick off Done means at the end.
Warning
Dhcpcd changes addresses, routes and DNS configuration. Do this from a local console or a maintenance connection if the interface carries your SSH session. The commands marked with sudo need elevated privileges.
1. Identify the interface and installed version
Do not copy an interface name from another machine. List the interfaces first, then record the one connected to the network you want to configure.
$ ip -brief link
enp0s31f6 UP 90:1b:0e:da:cc:ef <BROADCAST,MULTICAST,UP,LOWER_UP>
lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
$ dhcpcd --version
dhcpcd 10.0.6
Copyright (c) 2006-2023 Roy Marples
Your output will list different interfaces and may include extra compiled features. Do not use lo, a bridge, a Docker interface or a virtual interface unless you deliberately intend to configure it. Replace enp0s31f6 below with the interface you selected.
2. Test DHCP without changing the interface
Use test mode before a live change, especially on a remote host. It calls the normal hook runner with the TEST reason, prints DHCP variables and does not touch interface configuration or configuration files. The server does not offer a lease in this mode.
$ sudo dhcpcd --test enp0s31f6
dhcpcd-10.0.6 starting
enp0s31f6: soliciting a DHCP lease
interface='enp0s31f6'
protocol='dhcp'
reason='TEST'
dhcpcd exited
The exact variables and diagnostic lines depend on the received message. A missing DHCP response is not proof the interface is broken: check the cable or wireless association, VLAN, switch port and DHCP server first. If test mode produces no useful message, continue only once you understand that boundary.
Checkpoint
You have a real interface name, know the installed version, and have tried the non-configuring test. If you are returning later, start here.
3. Request a live address
Run dhcpcd for the single interface when you want a focused operation. The --waitip=4 option waits for an IPv4 address before backgrounding. It does not guarantee the DHCP server will provide a lease, and dhcpcd may use IPv4LL, also called link-local or APIPA, when DHCP fails.
$ sudo dhcpcd --waitip=4 enp0s31f6
dhcpcd-10.0.6 starting
enp0s31f6: soliciting an IPv4 lease
enp0s31f6: leased 192.0.2.25 for 86400 seconds
The address and messages are examples, not fixed output. The default lease timeout is 30 seconds, and the default reboot period is 5 seconds while dhcpcd tries an old lease before starting discovery. Need a foreground diagnostic run? Add --nobackground, and stop it with Ctrl-C only once you know whether the interface should remain configured.
Verify the result with the kernel's own view of the interface and route table:
$ ip address show dev enp0s31f6
$ ip route show dev enp0s31f6
$ sudo dhcpcd --dumplease enp0s31f6
--dumplease prints the stored lease for that interface. It can fail or print nothing useful when no lease has been saved. Lease files live below /var/lib/dhcpcd/, while runtime PID and socket files live below /run/dhcpcd/.
4. Make a narrow persistent change
dhcpcd reads /etc/dhcpcd.conf before command-line options. Put settings there when they should survive the next start, but keep the change tied to an interface block. This example prefers the wired interface and stops the resolv.conf hook from changing DNS:
interface enp0s31f6
metric 100
nohook resolv.conf
The lowest metric wins when dhcpcd manages more than one interface. nohook resolv.conf prevents that hook from touching DNS; it does not provide an alternative resolver configuration, so make sure another component owns DNS before applying it.
Warning
Editing this file changes future network configuration. Back it up, edit with an elevated editor, and do not paste a complete example over an existing distribution file.
$ sudo cp -p /etc/dhcpcd.conf /etc/dhcpcd.conf.before-guide
$ sudoedit /etc/dhcpcd.conf
$ sudo dhcpcd --rebind enp0s31f6
--rebind reloads the configuration and rebinds the interface. It can interrupt traffic and may replace the address or routes. If you only need to renew existing addresses without reloading the file, use sudo dhcpcd --renew enp0s31f6 instead.
Recovery
Undo this example by deleting the three added lines, or restore the backup if it holds the previous known-good file:
$ sudo cp -p /etc/dhcpcd.conf.before-guide /etc/dhcpcd.conf
$ sudo dhcpcd --rebind enp0s31f6
5. Handle common failure modes
- Second instance already managing the interface? Inspect the existing process and distribution service before starting another one. Use
sudo dhcpcd --exit enp0s31f6only when you intend to stop that instance and de-configure the interface. - Server hands out an unwanted address?
--request 192.0.2.25is only a request, not a reservation. Configure the reservation on the DHCP server instead. - Need to keep a manual address but still take DHCP options? Use
--inform 192.0.2.25/24with the correct local address and network. INFORM does not obtain a lease and fails rather than falling back to IPv4LL. - DHCP failure must not produce a link-local address? Add
noipv4llto the relevant configuration or use--noipv4llfor one run. This removes a fallback, it does not fix the DHCP path. - Server not answering at all? Use
--debugfor additional stderr and syslog messages. Avoid changing client identifiers, vendor class IDs or authentication settings until you have evidence the server requires it.
Done means
- Selected the correct interface, physical or intentionally managed, not copied from another machine.
- Tested before the live change.
dhcpcd --testran first where remote access mattered. - Confirmed the lease.
ip address,ip routeanddhcpcd --dumpleaseagree with what you intended. - Kept any config change safe. A
dhcpcd.confedit is backed up, scoped to the right interface and reversible. - Know who owns DNS, dhcpcd or another local service.