Skip to content

Linux Foundations / Follow traffic and find the fault ยท Step 26 of 46

Lesson: dhclientSwitch
โ† Linux Foundations

Network operations

dhclient

Request and release DHCP leases with dhclient and know when your system uses something else.

Most machines do not have a hand-typed IP address. They ask for one using DHCP, the Dynamic Host Configuration Protocol. dhclient is the DHCP client from the ISC DHCP project.

How a lease is obtained

DHCP for IPv4 usually takes four messages:

  1. Discover: the client looks for servers.
  2. Offer: a server proposes an address.
  3. Request: the client asks for that offer.
  4. Acknowledge: the server confirms it.

The result is a lease: an address lent for a limited time, normally with a subnet mask, gateway and DNS servers. The client renews it before it expires.

Is it still on your system?

ISC ended maintenance of its DHCP software in 2022. Many distributions now use NetworkManager's built-in client, systemd-networkd or dhcpcd, and may not ship dhclient at all. Check with:

$ command -v dhclient

No output means it is not installed or not in your path. If another tool manages the interface, do not run dhclient on it too, as the two can fight.

Requesting a lease

Use a test machine, and replace eth0 with your interface:

$ sudo dhclient -v eth0
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3
DHCPOFFER of 192.168.1.50 from 192.168.1.1
DHCPREQUEST for 192.168.1.50 on eth0 to 255.255.255.255 port 67
DHCPACK of 192.168.1.50 from 192.168.1.1

The output is shortened and varies by version. -v prints the conversation.

Releasing and renewing

$ sudo dhclient -r eth0
$ sudo dhclient eth0

-r releases the current lease and stops the running client. Running dhclient again asks for a new lease. You may well get the same address back.

Releasing on the interface carrying your SSH session will disconnect you before you can type the second command.

Where information is kept

Configuration is usually /etc/dhcp/dhclient.conf. Lease records are commonly under /var/lib/dhcp/ on Debian-based systems and /var/lib/dhclient/ on Red Hat-based systems.

Try it

  1. Run command -v dhclient to see whether you have it.
  2. Run ip -br addr show and note your current address.
  3. In a virtual machine with console access, release and renew, then compare the address.

Check your understanding

dhclient

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.