If you searched for a way to force a dhclient renew lease over remote SSH, the first thing to know is that the common one-liner can cut the branch you are sitting on. sudo dhclient -r eth0 && sudo dhclient -v eth0 gives up the address before asking for a new one, and the -x flag often recommended as the “safe” alternative still runs a teardown script on most Linux systems. This guide shows a safer order of operations: check what owns the interface, avoid releasing the lease unless you truly need a new address, and keep an out-of-band path ready. It also gives you a detached sequence for the cases where a release is unavoidable, plus verification and rollback commands.
Table of Contents
- Why the usual release-and-renew recipe breaks SSH
- Pre-flight checks before you change anything
- Find out who owns the interface
- What the main dhclient options actually do
- The SSH-safe renewal: keep the current lease
- If you must force a fresh exchange
- Verify the new lease
- Rollback plan if SSH does not return
- Conclusion
Why the usual release-and-renew recipe breaks SSH
dhclient -r does two jobs: it releases the current lease and stops the running client recorded in the PID file. The dhclient manual also says the client script runs during that shutdown, and the script’s job is to unconfigure the interface. On a remote host, that removes the IP address your SSH session is using. The TCP connection no longer has a local address and route, so the session stalls or dies.
The -x flag looks like a loophole. It stops the running client without releasing the lease, so the DHCP server still considers the address bound to your MAC address. But -x still invokes dhclient-script with a shutdown reason, and the dhclient-script manual lists STOP and RELEASE among the events where the script should unconfigure or shut down the interface. On the common Debian, Ubuntu, and RHEL-style scripts, that means the address and default route are removed. You skip the DHCPRELEASE packet, but you still lose the local address.
That release is usually unnecessary. The dhclient manual notes that the client normally does not release its lease because the DHCP protocol does not require it; release exists mainly for cable ISPs that expect notification. RFC 2131 also treats DHCPRELEASE as optional and explicitly allows a client to renew before T1, the first renewal timer.
There is one more trap: a normal dhclient start does not kill an existing client. Only -r and -x stop the process recorded in the PID file. If you launch a second client on an interface that already has one, the two can fight over the address, and the logs fill with add and remove events.
Pre-flight checks before you change anything
Collect the current state first. If the change goes wrong, these details are your rollback material.
| Check | Command | Why it matters |
|---|---|---|
| Interface name and link state | ip -brief link | Using the wrong name can change the wrong network. |
| Current address and prefix | ip -4 addr show dev eth0 | You need the old address to reconnect and roll back. |
| Default route | ip route show default | A lease without a usable gateway can still leave you unreachable. |
| DHCP process | pgrep -a dhclient | Confirms whether dhclient is actually running. |
| Network service | systemctl is-active NetworkManager systemd-networkd | Tells you whether another service owns the interface. |
| Lease details | sudo cat /var/lib/dhcp/dhclient.leases | Shows the old IP and the renew, rebind, and expire timers. |
| DNS configuration | resolvectl status eth0 or cat /etc/resolv.conf | DNS may change with the new lease. |
| SSH listener | `ss -tlnp \ | grep ':22'` |
| Out-of-band access | Provider console, serial console, IPMI, or hypervisor console | The only reliable recovery path if the address disappears. |
Save the important details in one file:
{ ip -4 addr show dev eth0 ip route show default cat /etc/resolv.conf } | sudo tee /root/pre-dhcp-renew.txt A second SSH session is useful for watching logs, but it is not a fallback. It travels over the same interface and the same address, so it disappears with the first session.
Find out who owns the interface
Do not start dhclient on an interface that another service manages. Identify the owner first, then use that service’s own renew or reconnect operation.
| Evidence | Likely owner | What to use instead |
|---|---|---|
pgrep -a dhclient shows a process, and NetworkManager and systemd-networkd are inactive | Standalone dhclient | The dhclient options in this guide. |
systemctl is-active NetworkManager returns active, and nmcli device status shows the link | NetworkManager | nmcli commands. |
systemctl is-active systemd-networkd returns active, and networkctl status eth0 shows the link | systemd-networkd | networkctl renew eth0. |
/etc/network/interfaces contains iface eth0 inet dhcp, and ifup --version works | ifupdown scripts | ifup or a full interface cycle, with console access. |
systemctl status dhclient@eth0 shows a running unit | A systemd unit wrapping dhclient | systemctl restart dhclient@eth0, with console access. |
pgrep -a dhcpcd shows a process | dhcpcd | dhcpcd has its own renewal commands; the dhclient flags here do not apply. |
If more than one of these is present, stop and resolve the ownership conflict before changing anything. Starting a second client on a managed interface is a reliable way to make the address flap.
What the main dhclient options actually do
Before choosing a flag, it helps to see how the dhclient command-line options for release, stop, and lease acquisition fit into the full lease lifecycle.
| Option | What it does | Effect on an SSH session |
|---|---|---|
-r | Releases the current lease and stops the running client. The script runs with the RELEASE reason. | The address is removed and the session drops. |
-x | Stops the running client without sending DHCPRELEASE. The script runs with a shutdown reason. | The address is still removed by the standard script, so the session drops too. |
-v | Enables verbose output. | Safe by itself, but dhclient -v eth0 on a host that already has a client starts a competing client. |
-1 | Tries to get a lease once and exits with code 2 on failure. | Useful in scripts, but it is still a separate client process. |
-d | Runs in the foreground and implies -v. | The process is tied to the terminal and may receive SIGHUP when SSH drops. |
-sf | Uses an alternate network configuration script. | Advanced: a no-op script can prevent the teardown. |
-lf | Uses an alternate lease file. | Useful for testing or preserving a copy of the lease database. |
The dhclient manual documents the default lease file as /var/lib/dhcp/dhclient.leases and the default PID file as /var/run/dhclient.pid. Red Hat–family systems sometimes use /var/lib/dhclient/dhclient.leases instead, so confirm the path on your host.
The SSH-safe renewal: keep the current lease
The safest renewal is the one that never removes the address. In most cases you do not need to force anything: a running dhclient renews automatically at T1, which is typically half of the lease lifetime. Check the timers:
sudo grep -E 'renew|rebind|expire' /var/lib/dhcp/dhclient.leases | tail -n 6 If the renew time is close, wait for the client to do its job. If the lease is already in the rebinding phase, check the logs with journalctl -t dhclient before intervening.
If systemd-networkd owns the interface
systemd-networkd has a dedicated renew command. The networkctl manual describes networkctl renew as renewing dynamic configurations such as addresses received from a DHCP server:
sudo networkctl renew eth0 networkctl status eth0 This asks networkd to renew the dynamic configuration rather than tearing the link down. It is the cleanest option on a systemd-networkd host.
If NetworkManager owns the interface
Use NetworkManager’s own tools rather than dhclient. The nmcli manual documents nmcli as the command-line control tool for NetworkManager connections:
nmcli device status nmcli connection show --active sudo nmcli device reapply eth0 nmcli device reapply applies the active profile to the device without a full down/up cycle. It is gentler than a reconnect, but it is intended for applying profile changes, not as a guaranteed lease-renewal command. For a full reactivation, use sudo nmcli connection up "<connection-name>" and expect a possible blip. Avoid nmcli connection down over SSH unless you have console access.
If standalone dhclient owns the interface
There is no supported dhclient flag that forces an immediate renewal while leaving the running client and the address untouched. dhclient renews at T1 on its own. If you need a fresh exchange now, use one of the approaches in the next section.
If you must force a fresh exchange
Option A: keep the address with a no-op stop script
This is an advanced sequence that uses two documented options together in an undocumented way. The -x flag stops the old client without sending DHCPRELEASE, and -sf /bin/true points that invocation at a no-op script so the STOP event cannot flush the address. The old IP, route, and DNS configuration stay in place. You then start a fresh dhclient, which reads the existing lease file and sends a DHCPREQUEST for the lease already bound to your MAC address.
# 1. Save the current lease and network state sudo cp -a /var/lib/dhcp/dhclient.leases /root/dhclient.leases.bak ip -4 addr show dev eth0 | sudo tee /root/eth0-before.txt ip route show default | sudo tee -a /root/eth0-before.txt # 2. Stop the old client without releasing the lease or running the teardown script sudo dhclient -x -sf /bin/true eth0 # 3. Start a new client; it should request the lease already in the lease file sudo dhclient -v eth0 If the server acknowledges the request, the address is renewed and SSH never loses its local IP. If the server rejects the request or offers a different address, the session may drop. This is not an officially documented renewal recipe, so test it on a lab VM or with console access first. Some builds may deconfigure the interface on the SIGTERM that -x sends to the old process, before the no-op script runs.
To make the sequence survive an SSH disconnect, run it as a transient systemd unit. The systemd-run manual explains that systemd-run starts a command in a clean, detached service environment managed by the service manager:
sudo systemd-run --unit=dhclient-renew --collect /bin/sh -c \ '/sbin/dhclient -x -sf /bin/true eth0; sleep 1; /sbin/dhclient -v eth0' Check the result with systemctl status dhclient-renew and journalctl -u dhclient-renew --no-pager. Change the unit name if one with that name already exists.
Option B: release and renew in a detached unit
Use this when you need a genuinely new lease, or when the DHCP server requires a release before it will hand out a different address. It will remove the current address, so treat the SSH session as disposable.
sudo systemd-run --unit=dhclient-rebind --collect /bin/sh -c \ 'sleep 15; /sbin/dhclient -r eth0; /sbin/dhclient -v eth0' The 15-second sleep gives you time to open the console. The release then runs, the address is flushed, and SSH drops. The second command reacquires a lease even though your session is gone. Reconnect to the old address first; if that fails, use the console to read the new address.
If systemd-run is unavailable, nohup can keep the sequence alive after the hangup:
sudo nohup /bin/sh -c 'sleep 15; /sbin/dhclient -r eth0; /sbin/dhclient -v eth0' \ >/root/dhclient-rebind.log 2>&1 & nohup ignores SIGHUP, so the commands continue after the SSH session ends. Unlike a transient systemd unit, there is no service manager supervising the process, so check the log file afterwards.
Verify the new lease
Reconnect and confirm the whole path, not just the address:
ip -4 addr show dev eth0 ip route show default resolvectl status eth0 # or: cat /etc/resolv.conf ping -c 3 <gateway> sudo grep -E 'renew|rebind|expire' /var/lib/dhcp/dhclient.leases | tail -n 6 ss -tlnp | grep ':22' Check the following:
- The new address and prefix length are what you expect.
- A default route exists and points at the correct gateway.
- DNS resolution works, either through
systemd-resolvedor the nameservers in/etc/resolv.conf. - The gateway responds to pings.
- The lease file shows fresh
renew,rebind, andexpiretimestamps. - sshd is still listening on port 22.
If systemd-networkd owns the link, networkctl status eth0 shows the lease and network details. If NetworkManager owns it, nmcli -f DHCP4 device show eth0 shows the DHCPv4 options.
Rollback plan if SSH does not return
If the host disappears and you have console access, restore the old address temporarily:
sudo ip addr add <old-ip>/<prefix> dev eth0 sudo ip route replace default via <old-gateway> dev eth0 The ip-address manual documents ip address add as the command that attaches a protocol address to a network device. Only restore the old address if you are confident it has not been reassigned to another host; otherwise you create an address conflict.
If DNS is broken, point the resolver at the old server temporarily:
sudo resolvectl dns eth0 <old-dns-server> If DHCP is badly broken and the host is still reachable from the console, a reboot is often the cleanest recovery: dhclient reads the saved lease file and retries from a known state. Do not reboot a remote host without console access.
Conclusion
dhclient -r and dhclient -x are not safe renew switches on a remote SSH host. -r releases the lease and removes the address, and -x skips the DHCPRELEASE but still runs a shutdown script that removes the address on standard Linux systems. The safest renewal is the one that never releases the lease: let dhclient renew at T1, or use networkctl renew or NetworkManager’s own tools when those services own the interface.
When standalone dhclient must be forced, the closest thing to a zero-downtime sequence is stopping the old client with -x -sf /bin/true and immediately starting a fresh client so it can request the existing lease. When a real release is required, run the release and renew in a detached systemd-run unit or under nohup, and keep a console path open. Either way, verify the address, default route, DNS, lease timers, and SSH listener before you close the console.
