49

I know there is a simple command for this, but how do I tell my Ubuntu server instance to request a new IP address from the DHCP server on eth0?

1
  • +1 for being Heat Miser (w/ pic!), haha.
    – nedm
    Jun 12, 2009 at 5:30

4 Answers 4

49
dhclient eth0

man page: dhclient

5
  • I get eth0: interface not found or invalid
    – Adam
    Mar 22, 2019 at 9:57
  • @Adam type ifconfig to see what are interfaces available on your system. Mar 26, 2019 at 13:57
  • this answer still works but is it the current recommended method or has this been superseded by anything better? is this the official method? how does Ubuntu Server internally create the network connection if you have an ethernet connection available at install time?
    – warsong
    Jul 3, 2020 at 22:12
  • 1
    @warsong as I remember from past, Install screen will let you choose between manually entering IP and DHCP. From docs I can now see, that by default it uses DHCP and shows you the address: ubuntu.com/tutorials/install-ubuntu-server#7-networking Cannot comment if dhclient is the most up-to-date command to be used. As for ifconfig, there is info that it is old and that ip should be used (ip link show). ubuntu.com/blog/… Jul 6, 2020 at 9:44
  • If it's not found use with sudo Mar 6, 2021 at 20:41
47

To release the current IP address:

$ sudo dhclient -r

To obtain a fresh lease:

$ sudo dhclient 
3
  • 4
    the OP may wants to run this inside a screen and actually do a "sudo dhclient -r <interface> && sudo dhclient <interface>" otherwise connectivity may be lost and he needs to get on site to restore the network link. That is if there is no out of bands management installed. Jun 12, 2009 at 6:55
  • 1
    Interesting, why is doing the release, then obtain better than just the sudo dhclient eth0? Thanks!
    – Heat Miser
    Jun 12, 2009 at 18:05
  • 5
    Just restarting dhclient will usually reassign the same IP address if the server doesn't object. If you release the address first, the server and client know to renegotiate a new one (although it could possibly be the same one you had). May 15, 2010 at 19:37
18

Another issue I ran in to was that dhclient kept requesting the same IP from the DHCP server. Running the command dhclient -r did not resolve this. Therefore, after reading the man pages more thoroughly, I found that if I edited the file /var/lib/dhcp3/dhclient.leases to remove all lease references to the specific adaptor, in my case eth0. Then running sudo dhclient eth0 worked as expected and assigned me a new/different IP.

My situation was perhaps unique, but it required that my server pull an address from a higher range than was previously issued. The DHCP server was configured to do this, unless a specific IP address was requested regardless of the range. Since dhclient was specifically requesting the old IP address, based on the information in the dhclient.leases file, the DHCP server was always returning the same address.

2
  • 2
    Agree: situation I have had and just had to remind myself about again is the situation where you have a system which was getting a random IP address, but to which you assign a new (different) statically leased IP address, assigned by MAC. The issue is that if your DHCP client still has a valid lease in dhclient.leases, it does not actually ask the server for a new IP address: it just reuses the lease which it thinks is still valid. So dhclient -r effectively does nothing. Deleting leases file first, followed by dhclient -r, and all is well.
    – liamf
    Sep 29, 2011 at 23:28
  • is this an ubuntu-specific issue? It's happened to me before with some ubuntu clients
    – Daniel
    Jan 27 at 10:01
-3

When you run "sudo /etc/init.d/dhcp3-server restart" does it give something like:

Stopping DHCP server: dhcpd3. Starting DHCP server:dhcpd3.

If not, it's not running...

Then just be sure, check if your client sends out a request for a lease, take a look at your /var/logs/deamon.log file. There should be a bunch of DHCP requests in there. If not, the problem is with your client (and we will take it from there).

If your client is ok, just forget about firestarter for the moment and let's try to get it working without it. To make sure your DHCP server is up and running. Type "sudo /etc/init.d/dhcp3-server stop" and then "sudo /etc/init.d/dhcp3-server start". Then it should be running, assuming it's properly installed on your box.

I have included a copy of my dhcpd.conf file.

Finally, take a look at your server's /var/log/messages file if it gets the requests and replies to it with a valid lease. It also might give you an idea what's wrong with your configuration file (if there's something wrong with it ofcourse). If you can't make anything of this, post your messages file and I will take a look lateron.

goodluck

Rajat

1
  • 3
    He's talking about the DHCP client, not the server.
    – mikl
    Jun 12, 2009 at 7:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .