41

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?

Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
Heat Miser
  • 535
  • 1
  • 5
  • 7

4 Answers4

43

dhclient eth0

Janis Veinbergs
  • 1,545
  • 4
  • 23
  • 34
  • I get `eth0: interface not found or invalid` – Adam Mar 22 '19 at 09:57
  • @Adam type `ifconfig` to see what are interfaces available on your system. – Janis Veinbergs Mar 26 '19 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 03 '20 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: https://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`). https://ubuntu.com/blog/if-youre-still-using-ifconfig-youre-living-in-the-past – Janis Veinbergs Jul 06 '20 at 09:44
  • If it's not found use with sudo – walnut_salami Mar 06 '21 at 20:41
42

To release the current IP address:

$ sudo dhclient -r

To obtain a fresh lease:

$ sudo dhclient 
Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
LukeR
  • 3,086
  • 2
  • 29
  • 25
  • 4
    the OP may wants to run this inside a screen and actually do a "sudo dhclient -r && sudo dhclient " 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. – Martin M. Jun 12 '09 at 06:55
  • 1
    Interesting, why is doing the release, then obtain better than just the sudo dhclient eth0? Thanks! – Heat Miser Jun 12 '09 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). – Martijn Heemels May 15 '10 at 19:37
16

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.

abrightwell
  • 161
  • 1
  • 3
  • 1
    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 '11 at 23:28
-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

Rajat
  • 3,329
  • 21
  • 29