55

The environment is Debian, although the answer will apply to all distributions.

Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
GeneQ
  • 407
  • 2
  • 8
  • 17

6 Answers6

68

You can also use this command:

dhclient -r interface

Where interface is the device you want to get a new address for.

dhclient -r eth0

The -r flag forces dhclient to first release any leases you have, you can then use this command to request a new lease:

dhclient eth0

From man dhclient:

   -r     Tell  dhclient  to  release the current lease it has from the 
          server.  This is not required by the DHCP protocol, but some 
          ISPs require their clients to notify the server if they wish 
          to release an assigned IP address.
Trevor Karjanis
  • 101
  • 1
  • 4
Jason Abate
  • 441
  • 4
  • 3
  • Also a good way to do it :) – Frenchie Jul 20 '09 at 02:31
  • 1
    After this command my Debian failed to get a new IP, but after a reboot I was assigned to a new one, so it work's! – Damien Sep 09 '11 at 09:16
  • 4
    For me this only releases the lease and uncofigures the interface. No new IP is obtained afterwards. – cgogolin Jan 15 '15 at 09:33
  • 1
    Which is a total bummer if you're primary interface is ssh... – Eric Nord Apr 03 '19 at 03:55
  • 1
    @EricNord - You can still do this via SSH. Use the 'at' command to schedule a one-time command, 1 minute in the future or less, disconnect your SSH session then reconnect. You could even automate it, and reconnect to the same host via Multicast DNS (assuming you have that running, most home networks do) – Scott Prive Sep 10 '21 at 14:24
  • I don't know if something changed but on my NUC doing this *works* but it adds an address to my ethernet, *without* removing the old one. So now my computer accepts packets at both addresses. That's a bit annoying. – Louis Feb 24 '22 at 14:43
17

Either of the following should get it to renew.

/etc/init.d/networking restart

or

ifdown eth0; ifup eth0

I wouldn't recommend running either over an SSH connection, although you'll probably get away with the first one if it doesn't come back with a new ip address.

Frenchie
  • 1,272
  • 9
  • 14
  • 2
    SSH connections will tolerate a few seconds of "disconnect" provided that you get the connection back up in a few seconds at the same IP address. Under these conditions, I have never lost a connection during `/etc/init.d/networking restart`, even when it was taking more than 5 seconds to come back up... – Avery Payne Jul 20 '09 at 02:58
  • Doesn't this require administrative priviledges? – Peter Mortensen Dec 11 '15 at 12:21
  • Worst case you reconnect. If you're trying to automate this, see mDNS and 'at' command, and use a wrapper script to orchestrate the change and the reconnect. – Scott Prive Sep 10 '21 at 14:25
15

Would comment p.campbell, but I have only 1 reputation and therefore cannot, first I review installed interfaces:

ip addr

release IP from selected interface (e.g. eth0, eth1, enp1s0, sit0, wlan0,...):

sudo dhclient -r *interface*

request new IP from DHCP server (alert on error):

sudo dhclient -1 *interface*

check IP:

ip addr

Ubuntu 16.04 LTS confirmed

BFGoody
  • 1
  • 1
  • 2
10

If you're using the dhcpcd tool then:

dhcpcd -k interface
dhcpcd -n interface

The first says to release and deconfigure the interface, and the second says to reload configuration and rebind the interface again.

Jruv
  • 101
  • 3
koenigdmj
  • 1,055
  • 7
  • 12
8

If the MAC address of the interface isn't changed, the DHCP server may assign it the same address when renewing. Therefore, a simple release and renew with dhclient may not acquire a new address. Change the MAC address and acquire a new IP address with the following commands. Don't forget to write the original down if you need to revert back to it at a later time.

ifconfig <interface> down
ifconfig <interface> hw ether <MAC address>
ifconfig <interface> up
Trevor Karjanis
  • 101
  • 1
  • 4
  • 2
    This was so helpful, thank you! No number of `dhclient -r` or `ifconfig down` gave me a new IP address on my work network, until I changed the MAC address to something random using that command. – Migwell Nov 19 '19 at 00:48
0

In systems where NetworkManager is on, running...

nmcli con

...gets you a connection list, and running...

nmcli con down id 'Connection Name'
nmcli con up id 'Connection Name'

takes the connection down and back up

Osqui
  • 135
  • 8