Linux Force DHCP client (dhclient) to renew ip address

by Vivek Gite on November 15, 2007 · 21 comments

Q. I'm using Ubuntu Linux. How to force Linux to reacquire a new IP address from the DHCP server? What is the command in Linux equivalent to Windows' "ipconfig /renew" Command?

A. You need to use Dynamic Host Configuration Protocol Client i.e. dhclient command. The client normally doesn't release the current lease as it is not required by the DHCP protocol. Some cable ISPs require their clients to notify the server if they wish to release an assigned IP address.

Linux renew ip command

The -r flag explicitly releases the current lease, and once the lease has been released, the client exits. For example, open terminal and type the command:
$ sudo dhclient -r
Now obtain fresh IP:
$ sudo dhclient

There is no need to restart network service. Above command should work with any Linux distro such as RHEL, Fedora, CentOS, Ubuntu and others. On a related note you can also try out the following commands:
# ifdown eth0
# ifup eth0
# /etc/init.d/network restart

OR
# /etc/init.d/networking restart

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 21 comments… read them below or add one }

1 Rajesh June 14, 2008

Resolution provided was short but very effective.
Helped me to resolve the issue.

Great work

Thanks
Rajesh

Reply

2 synick November 27, 2008

Hi,

This worked great, I was having a bit of problems thought worked them out in the end, thought I would share.

I unplugged the network cable, then plugged back in a couple minutes later. Couldn’t access network, tried dhclient -r command and didn’t work. Found that dhcpcd was still running, so done a killall -9 dhcpcd then executed dhclient…worked!

Reply

3 thehuyvb June 22, 2009

Thanks so much! it’s work ^^

Reply

4 anon July 8, 2009

Thanks!

Reply

5 Thamizhannal August 7, 2009

This command worked me..thanks a lot

Reply

6 David Balažic September 1, 2009

This does not work on Ubuntu 9.04

It seems that network manager runs it own copy of dhclient.

Reply

7 Schmid Hans-Peter October 7, 2009

Works for me on Ubuntu 9.04. It seems to me, that the network-manager does not notice the change. After sudo dhclient -r the command ifconfig eth0 shows no ip address at the interface. After sudo dhclient the command ifconfig eth0 shows an ip address again.

Thank you

Reply

8 David Balažic October 7, 2009

Nope. After sudo dhclient -r the interface still has the IP address. See details: http://pastebin.com/f8d2a4e2

Reply

9 How to Assign IP Address In DHCP in Linux November 23, 2009

Dear sir
Please Help Me
How t o Assign IP Address For DHCP Client Linux..

Thanks

Reply

10 Eduardo Calvillo February 1, 2010

Thank you for the recommendation, it works good.

Reply

11 Flyte February 18, 2010

I set up static DHCP assignments and then needed to switch my server over to DHCP. To do this remotely I simply put the two commands on a single line:

dhclient -r; dhclient

If you’ve set up the static DHCP to use the IP address that you’ve already given it then you shouldn’t become disconnected from your SSH session :)

Reply

12 PCG May 27, 2010

briliant!

Reply

13 jeffory November 17, 2010

@ David Balažic

It wasn’t working for me for me with Ubuntu 10.04…[continued if this posts]

Reply

14 Christian January 19, 2011

Thank for your solution, really help me.

Reply

15 jamkomo February 4, 2011

Well, it releases them, but when I renew it, it gives me the same ip back. I wanted a new IP. Is there way to force a NEW one?

Reply

16 Philip October 30, 2011

You need to tell the dhcp server to issue a different one, typically I dhcp server will if it can issue the same address.

You may be able to tell it to forget what it last issued, or you can usually make a mapping between the mac address of your nic and the ip you want, but generally unless you do something on the server it wil reissue the same address.

Reply

17 Mike Bethany February 19, 2011

If you’re having problems getting your Linux distro to get a new IP the easiest thing to do is to just reboot your router (assuming you can do that). If that doesn’t work you can add the old address as a statically assigned DHCP address to a bogus MAC address. This will lock the Linux box out of it’s old address and force it to get the new address.

Reply

18 David Balažic March 19, 2011

More detail, about this not working on Ubuntu:
sudo dhclient -r -pf /var/run/dhclient-eth1.pid -lf /var/lib/dhcp3/dhclient-eth1.lease eth1

This kill the running dhcp daemon which is noticed by Network Manager which then immediately downs the interface, so the dhclient can not send the DHCPRELEASE packet.

The solution is to disable NM (right clik on its icon and uncheck the first option “Enable Netwroking” – this is so on Ubuntu 10.10, other version might look a bit different), kill existing dhclient processes, then establish the connection manually, run dhclient eth0 , then run the above dhclient command to release the IP.

For connection to WPA protected WLAN networks follow the description on http://linux.icydog.net/wpa.php

(In windows this is justa matter of running “ipconfig /release wirelless*” :P )

Reply

19 David Balažic March 19, 2011

Oh, webmaster please fix the typos in my previous post… :-)
(for network device names, use the same one of course, above I used ince eth0, then eth1)

Reply

20 kOz April 5, 2011

Fantastic! Worked like a charm on Ubuntu 10.10! Thanx!

Reply

21 Danilo September 7, 2011

Just what i needed!

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">




Previous post:

Next post: