How to Renew DHCP IP Address on Ubuntu Server via Command Line


2 views

When your Ubuntu Server obtains an IP address via DHCP, the lease typically has an expiration period. You might need to manually renew this address when:

  • Network configuration changes occur
  • You're troubleshooting connectivity issues
  • Moving between networks (especially in cloud environments)

The primary tool for DHCP operations is dhclient. To release and renew your IP address on interface eth0:

sudo dhclient -r eth0  # Release current lease
sudo dhclient eth0     # Request new lease

For systems using ifupdown (common in older Ubuntu versions):

sudo ifdown eth0
sudo ifup eth0

Note: This method completely restarts the network interface.

After renewal, verify your new IP assignment with:

ip addr show eth0
# or alternatively
ifconfig eth0

For automatic renewal at specific intervals, edit /etc/dhcp/dhclient.conf:

interface "eth0" {
    send host-name "your-hostname";
    request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, host-name;
    renew 2 0 0 0;
    rebind 2 0 0 0;
    expire 2 0 0 0;
}

If you encounter problems, check the DHCP server logs:

sudo tail -f /var/log/syslog | grep dhclient

For more verbose output during renewal:

sudo dhclient -v eth0

On cloud platforms like AWS or Azure, you might need to use platform-specific tools:

# For AWS EC2
sudo service network restart
# For Azure
sudo systemctl restart walinuxagent

For automated renewal in scripts:

#!/bin/bash
INTERFACE="eth0"
LOG_FILE="/var/log/dhcp_renewal.log"

echo "$(date) - Renewing DHCP lease for $INTERFACE" >> $LOG_FILE
sudo dhclient -r $INTERFACE && sudo dhclient $INTERFACE >> $LOG_FILE 2>&1

When working with Ubuntu Server, network interfaces configured via DHCP automatically attempt to renew their leases periodically. However, there are situations where you might need to manually trigger this process:

  • After changing DHCP server configuration
  • When troubleshooting network connectivity issues
  • If you suspect IP address conflicts
  • When moving a server between network segments

The primary tool for DHCP operations on Ubuntu is dhclient. To release and renew your IP address on interface eth0:

sudo dhclient -r eth0  # Release current lease
sudo dhclient eth0     # Request new lease

For systems using netplan (Ubuntu 17.10 and later):

sudo netplan apply

For systems using ifupdown:

sudo ifdown eth0 && sudo ifup eth0

Check your new IP assignment with:

ip addr show eth0

Or for detailed DHCP information:

cat /var/lib/dhcp/dhclient.eth0.leases

If you encounter problems:

# Check DHCP client logs
sudo journalctl -u systemd-networkd -u NetworkManager --no-pager -n 50

# Verify DHCP server availability
nc -vzu your-dhcp-server-ip 67

To schedule regular renewals, create a cron job:

# Add to /etc/crontab
0 3 * * * root /sbin/dhclient -r eth0 && /sbin/dhclient eth0