SkillPilotAI

dhclient and dhcpcd

dhclient and dhcpcd are command-line DHCP clients on Linux: they ask a DHCP server for an IP, gateway and DNS, configure the interface, and renew or release the lease. dhclient (ISC) is deprecated upstream but still common on Debian/Ubuntu; dhcpcd is the default on Raspberry Pi OS and Arch.

79.1 Why is it used?

  • Get, renew or release a DHCP lease by hand while debugging a network.
  • See the DORA exchange live (-v / -d) to check whether an Offer even arrives.
  • Test what a server would give without changing the interface (dhcpcd -T).
  • Windows/macOS do not have these tools; on Windows use ipconfig /release and /renew.

79.2 How it works

dhclient DORA in the lab network
  1. 1.pc1 (02:79:00:00:00:11) has no IPv4: dhclient broadcasts Discover

  2. 2.The switch n079-lan carries it to dnsmasq 192.168.99.2

  3. 3.dnsmasq sends an Offer of 192.168.99.111 back to pc1

  4. 4.pc1 sends a Request for 192.168.99.111

  5. 5.dnsmasq sends Ack: IP, gateway and DNS are set on eth0

Run DHCP tests only on a network you own

  • Lease 600 s: T1 (50%) = 300 s, unicast renew to the same server; T2 (87.5%) = 525 s, broadcast rebind to any server; at 600 s the IP is removed.

79.3 dhclient: get a lease

Terminal
ip -br addr show eth0dhclient -v -1 eth0ip -br -4 addr show eth0ip routecat /etc/resolv.confcat /var/lib/dhcp/dhclient.leases
Output
$ ip -br addr show eth0eth0@if1351      UP             fe80::79:ff:fe00:11/64$ dhclient -v -1 eth0Listening on LPF/eth0/02:79:00:00:00:11DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3DHCPOFFER of 192.168.99.111 from 192.168.99.2DHCPREQUEST for 192.168.99.111 on eth0 to 255.255.255.255 port 67DHCPACK of 192.168.99.111 from 192.168.99.2bound to 192.168.99.111 -- renewal in 245 seconds.$ ip -br -4 addr show eth0eth0@if1351      UP             192.168.99.111/24$ ip routedefault via 192.168.99.1 dev eth0192.168.99.0/24 dev eth0 proto kernel scope link src 192.168.99.111$ cat /etc/resolv.confsearch n079.labnameserver 192.168.99.2$ cat /var/lib/dhcp/dhclient.leases  fixed-address 192.168.99.111;  option routers 192.168.99.1;  option dhcp-lease-time 600;  option dhcp-renewal-time 300;  option dhcp-rebinding-time 525;  renew 0 2026/11/08 22:05:07;  expire 0 2026/11/08 22:11:02;

79.4 dhclient: release, stop and run options

Terminal
dhclient -r -v eth0dhclient -v -e IF_METRIC=100 eth0dhclient -x -v eth0printf 'timeout 10;\n' > /etc/dhcp/t10.confdhclient -v -1 -cf /etc/dhcp/t10.conf -p 1068 eth0
Output
$ dhclient -r -v eth0Killed old client processDHCPRELEASE of 192.168.99.111 on eth0 to 192.168.99.2 port 67$ dhclient -v -e IF_METRIC=100 eth0DHCPACK of 192.168.99.111 from 192.168.99.2bound to 192.168.99.111 -- renewal in 275 seconds.$ ip routedefault via 192.168.99.1 dev eth0 metric 100$ dhclient -x -v eth0Killed old client process$ dhclient -v -1 -cf /etc/dhcp/t10.conf -p 1068 eth0binding to user-specified port 1068DHCPDISCOVER on eth0 to 255.255.255.255 port 1067 interval 8No DHCPOFFERS received.Unable to obtain a lease on first try.  Exiting.
OptionMeaning
-4 / -6DHCPv4 (default) / DHCPv6
-1Try once; on failure exit with code 2
-d / -nwStay in foreground (implies -v) / daemonise at once
-v / -qVerbose / quiet (default)
-rSend DHCPRELEASE and stop the client
-xOnly stop the client, no Release
-e VAR=valPass a variable to the script (IF_METRIC=100)
-p PORTClient UDP port (default 68; server port becomes PORT-1)
-s ADDRSend to this server instead of broadcast
-cf / -lf / -pf / -sfConfig / lease / PID / script file

79.5 dhclient: DHCPv6

  • -6 uses four messages: Solicit, Advertise, Request, Reply; the address is added as /128.
  • -S is stateless: only an Info-Request, giving DNS but no address.
  • -P asks for prefix delegation; dnsmasq does not delegate prefixes, so it failed ('Lease failed to satisfy').
  • -T temporary addresses, -D LL/LLT chooses the DUID type (the client's permanent DHCPv6 identity), --address-prefix-len 64 changes the plen given to the script.
Terminal
dhclient -6 -v -1 eth0ip -br -6 addr show eth0dhclient -S -v -1 eth0
Output
$ dhclient -6 -v -1 eth0XMT: Solicit on eth0, interval 1030ms.RCV: Advertise message on eth0 from fe80::ccd9:1cff:fe95:47e3.RCV:  | | X-- IAADDR fd00:79::152XMT: Request on eth0, interval 950ms.RCV: Reply message on eth0 from fe80::ccd9:1cff:fe95:47e3.PRC: Bound to lease 00:01:00:01:32:83:ad:8c:00:00:00:00:00:00.$ ip -br -6 addr show eth0eth0@if1351      UP             fd00:79::152/128 fe80::79:ff:fe00:11/64$ dhclient -S -v -1 eth0PRC: Requesting information (INIT).XMT: Info-Request on eth0, interval 930ms.RCV: Reply message on eth0 from fe80::ccd9:1cff:fe95:47e3.PRC: Done.$ grep fd00 /etc/resolv.confnameserver fd00:79::2

79.6 dhclient: the script does the configuring

  • dhclient only talks DHCP; the dhclient-script sets the IP, routes and resolv.conf.
  • With -sf pointing at a tiny logging script, the log got BOUND with IP and lease, but eth0 got no IPv4.
  • PATH_DHCLIENT_DB / PATH_DHCLIENT_PID (and _CONF, _SCRIPT) override file paths; command-line options win.
  • --no-pid writes no PID file, so -r / -x cannot find that client later. omshell (OMAPI) states 2/3/4 = release/pause/resume (omshell is not in the Debian client package).
Terminal
cat /etc/dhcp/n079-hook.shdhclient -1 -sf /etc/dhcp/n079-hook.sh -lf /tmp/n079.leases -pf /tmp/n079.pid eth0cat /tmp/n079-hook.logip -br -4 addr show eth0
Output
$ cat /etc/dhcp/n079-hook.sh#!/bin/shecho "$reason ip=$new_ip_address gw=$new_routers lease=$new_dhcp_lease_time" >> /tmp/n079-hook.log$ cat /tmp/n079-hook.logPREINIT ip= gw= lease=BOUND ip=192.168.99.111 gw=192.168.99.1 lease=600$ ip -br -4 addr show eth0$

79.7 dhcpcd: controlling the daemon

dhcpcd: command to daemon, daemon to server
  1. 1.dhcpcd -w eth0 leases 192.168.99.112 and forks to the background

  2. 2.You run dhcpcd -n (or -N / -k)

  3. 3.The command signals the running daemon over its control socket

  4. 4.-n: the daemon reloads config and sends a Request; the server Acks

  5. 5.-k: the daemon sends a Release and removes the IP from eth0

Terminal
dhcpcd -4 -w eth0ps -C dhcpcd -o pid,cmddhcpcd -4 -U eth0dhcpcd -4 -N eth0dhcpcd -4 -n eth0dhcpcd -4 -k eth0grep DHCP /tmp/dnsmasq.log     # on the dhcp server
Output
$ dhcpcd -4 -w eth0eth0: offered 192.168.99.112 from 192.168.99.2eth0: leased 192.168.99.112 for 600 secondseth0: adding default route via 192.168.99.1forked to background, child pid 431$ ps -C dhcpcd -o pid,cmd    431 dhcpcd: eth0 [ip4]    432 dhcpcd: [privileged proxy] eth0 [ip4]    433 dhcpcd: [control proxy] eth0 [ip4]$ dhcpcd -4 -U eth0reason=BOUNDip_address=192.168.99.112routers=192.168.99.1domain_name_servers=192.168.99.2dhcp_lease_time=600dhcp_renewal_time=300dhcp_rebinding_time=525$ dhcpcd -4 -N eth0sending signal USR1 to pid 431$ dhcpcd -4 -n eth0sending signal HUP to pid 431$ dhcpcd -4 -k eth0sending signal ALRM to pid 431waiting for pid 431 to exitdhcp$ grep DHCP /tmp/dnsmasq.log22:02:58 ... DHCPREQUEST(eth0) 192.168.99.112 02:79:00:00:00:1222:02:58 ... DHCPACK(eth0) 192.168.99.112 02:79:00:00:00:1222:03:11 ... DHCPRELEASE(eth0) 192.168.99.112 02:79:00:00:00:12
dhcpcd optionSignal / effect
-n, --rebindHUP: reload config + rebind
-N, --renewUSR1: renew without reloading config
-k, --releaseALRM: release + deconfigure
-x, --exitDaemon exits
-g, --reconfigureRe-apply addresses and routes (e.g. after a VPN changed routes)
-U, --dumpleasePrint the current lease
-P / -VPrint PID file path / list hook variables (234 lines in the lab)

79.8 dhcpcd: fine tuning and restricting

  • -l 300 asks for a 300 s lease, -r requests an address, -m 100 route metric, -h hostname, -i vendor class (MSFT), -o requests an option (ntp_servers).
  • -S KEY=VAL sets a static address/gateway without any DHCP request; -1 oneshot exits after configuring.
  • -T test: prints the offer's variables and configures nothing.
  • -G no default route, -C HOOK skips a hook (resolv.conf kept 1.1.1.1), -L no IPv4LL (169.254), -X blacklists / -W whitelists a server, -Z/-z deny/allow interface patterns.
Terminal
dhcpcd -4 -1 -l 300 -h lab-pc2 -i MSFT -m 100 -r 192.168.99.140 -o ntp_servers eth0dhcpcd -4 -T eth0dhcpcd -4 -w -t 10 -X 192.168.99.2 eth0
Output
$ dhcpcd -4 -1 -l 300 -h lab-pc2 -i MSFT -m 100 -r 192.168.99.140 -o ntp_servers eth0eth0: soliciting a DHCP lease (requesting 192.168.99.140)eth0: offered 192.168.99.140 from 192.168.99.2eth0: leased 192.168.99.140 for 300 secondsexiting due to oneshot$ ip routedefault via 192.168.99.1 dev eth0 proto dhcp src 192.168.99.140 metric 100$ dhcpcd -4 -T eth0eth0: offered 192.168.99.140 from 192.168.99.2reason='TEST'new_ip_address='192.168.99.140'new_routers='192.168.99.1'new_dhcp_lease_time='600'new_domain_name_servers='192.168.99.2'$ ip -br -4 addr show eth0$$ dhcpcd -4 -w -t 10 -X 192.168.99.2 eth0eth0: soliciting a DHCP leaseeth0: blacklisted DHCP packet from 192.168.99.2eth0: blacklisted DHCP packet from 192.168.99.2eth0: probing for an IPv4LL addresstimed out

79.9 Comparison: dhclient vs dhcpcd

Pointdhclientdhcpcd
ProjectISC (deprecated upstream)Roy Marples, actively maintained
Default onDebian / Ubuntu (older)Raspberry Pi OS, Arch
ModelRuns per command, configures via dhclient-scriptLong-running daemon, controlled by signals
Release-r-k
Show leaseLease file-U
Test without changes--T

79.10 Common mistakes

  • Thinking dhclient -r and -x are the same: -r sends DHCPRELEASE (server frees the IP now), -x only stops the process (IP stays reserved until expiry).
  • Running two DHCP clients on one interface: they fight over the address and routes.
  • Replacing the script with -sf and wondering why eth0 has no IP: configuring is the script's job.
  • Using --no-pid and then expecting -r / -x to find the client.

79.11 Interview tips

  • Debug a DHCP client: watch the exchange (dhclient -v, dhcpcd -d), check the lease (dhclient.leases, dhcpcd -U), test with dhcpcd -T.
  • 10-minute lease with the server down: 5 min T1 renew (unicast), 8 min 45 s T2 rebind (broadcast), 10 min expiry and Discover again.
  • Setting the IP is done by dhclient-script, not dhclient itself.
  • One DHCP client per interface; release properly (-r / -k) so the server frees the IP.