html
When your Linux machine obtains an IP address via DHCP, it's actually leasing the address for a specific duration. The DHCP client (typically dhclient or systemd-networkd) handles this process automatically, but sometimes manual intervention is needed.
The most direct way to force a DHCP renewal is using the dhclient command:
sudo dhclient -r eth0 # Release current lease sudo dhclient eth0 # Request new lease
Replace "eth0" with your actual interface name (check with ip a
or ifconfig
). The -r
flag releases the current lease before requesting a new one.
For modern Debian systems using systemd-networkd:
sudo networkctl renew eth0 # Alternatively: sudo systemctl restart systemd-networkd
If using NetworkManager (common on desktop installations):
sudo nmcli con up id 'YourConnectionName' # Or to release/renew specifically: sudo nmcli c down id 'YourConnectionName' && sudo nmcli c up id 'YourConnectionName'
To modify DHCP client behavior permanently, edit /etc/dhcp/dhclient.conf
:
# Request specific options from DHCP server request subnet-mask, broadcast-address, routers, domain-name-servers; # Set lease timeout (in seconds) timeout 60; retry 10;
If renewal fails, check these logs:
journalctl -u systemd-networkd -f # For systemd systems tail -f /var/log/syslog # Traditional syslog dhclient -v eth0 # Run dhclient in verbose mode
To request a completely fresh lease (including new DNS servers and routes):
sudo dhclient -v -r eth0 sudo rm /var/lib/dhcp/dhclient.leases.eth0 sudo dhclient -v eth0
Warning: This completely clears the lease history for the interface.
Create a renewal script (e.g., /usr/local/bin/renew_dhcp.sh
):
#!/bin/bash INTERFACE=${1:-eth0} echo "Renewing DHCP lease for $INTERFACE" sudo dhclient -r $INTERFACE && sudo dhclient $INTERFACE exit $?
Make it executable with chmod +x /usr/local/bin/renew_dhcp.sh
.
After renewal, verify your new IP configuration:
ip a show eth0 ip route show cat /etc/resolv.conf
The Dynamic Host Configuration Protocol (DHCP) assigns IP addresses dynamically with a lease time. When you need to immediately acquire a new IP configuration rather than waiting for lease expiration, manual intervention is required.
The most straightforward method for Debian-based systems:
sudo dhclient -r eth0 # Release current lease
sudo dhclient eth0 # Request new lease
For modern systems using predictable network interface names (like enp0s3):
sudo dhclient -r enp0s3
sudo dhclient enp0s3
For systems using systemd-networkd (common in newer Debian/Ubuntu versions):
sudo networkctl renew eth0
Alternatively:
sudo systemctl restart systemd-networkd
If using NetworkManager (common in desktop environments):
sudo nmcli connection down "Wired connection 1"
sudo nmcli connection up "Wired connection 1"
After renewal, verify with:
ip a show eth0
dhclient -v eth0
To modify DHCP client behavior, edit /etc/dhcp/dhclient.conf
:
# Example configuration
interface "eth0" {
send host-name "myhost";
request subnet-mask, broadcast-address, routers;
require subnet-mask;
}
If renewal fails, check DHCP server logs or test with:
sudo dhclient -d -v eth0 # Debug mode
journalctl -u systemd-networkd -f # Monitor networkd logs