Network
The dhclient command
ISC DHCP client: asks the server for an IP and configures the chosen interface.
Most useful options
-1Tries to get a lease only once. If it fails, it exits with code 2.-vVerbose log messages, useful to follow each step of the exchange.-dForces the foreground, instead of moving to the background once the interface is configured. Implies -v.-nwGoes to the background right away, without waiting to get an IP.-rReleases the current lease and stops the running client, as recorded in the PID file.-xStops the running client without releasing the lease.-6Uses DHCPv6 instead of DHCPv4 to ask for the available IPv6 addresses.-lf ficheroUses another lease file. By default, /var/lib/dhcp/dhclient.leases.Copy-ready examples
$ sudo dhclient -v eth0asks for an IP on eth0 and shows each step of the exchange.$ sudo dhclient -1 -v eth0a single attempt. If the server does not answer, it exits with code 2 instead of waiting.$ ip -br addr show eth0checks which IP ended up on the interface. Changes nothing.$ sudo dhclient -r eth0warning: releases the current lease and stops the client. The interface may be left without an IP until the next request.You can try them in the browser terminal: it does not touch your computer.
Typical mistakes
- Configuring the interface requires root: that is why it runs with sudo.
- ISC stopped maintaining ISC DHCP, including dhclient, at the end of 2022. Many current systems get their IP with NetworkManager or systemd-networkd.
- With -nw the client goes to the background even if it gets no IP. To see what happens, use -v in the foreground.
- If the DHCP server does not answer, dhclient gets no IP: the fault is usually in the server or the network, not in the client.
Differences from similar commands
Related commands
FAQ
What does dhclient do step by step?
It sends DHCPDISCOVER, receives DHCPOFFER, sends DHCPREQUEST and receives DHCPACK with the assigned IP.
How do I release the IP without waiting?
With sudo dhclient -r eth0, which releases the lease and stops the client. If you only want to stop it, use -x.
What exit code does -1 give on failure?
It exits with code 2. Right after running it, echo $? shows that value.
More Network commands
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course