I am using modern versions of Ubuntu that use network-manager, and I would like release and renew my network settings through the commandline.

In the olden days when Ubuntu used the interfaces file, I would simply do: sudo /etc/init.d/networking restart but now that no longer works.

I am looking for functionality similar to Windows' ipconfig /release and ipconfig /renew.

How can I release and renew network settings from the commandline interface?

  • Which version of Ubuntu? Network Manager's tools have evolved over time. Have a look at manpages.ubuntu.com/manpages/xenial/en/man1/nmcli.1.html – muru May 4 '16 at 7:51
  • 2
    Did you try sudo /etc/init.d/network-manager restart? – migrc May 4 '16 at 8:50
  • What exactly is a "modern version of Ubuntu"? You should be more specific. – Rosamunda Mar 12 '17 at 17:30
  • 1
    A modern version of Ubuntu would be a current version. The answer could change over time. – David Mar 15 '17 at 21:17

To release and renew the IP address it is:

sudo dhclient -r eth0
sudo dhclient eth0

Or you can try a one-liner that grabs the default ethernet name from netstat:

NIC=$(netstat -r | awk '/default/ {print $NF}' | head -1); sudo dhclient -r $NIC && sudo dhclient $NIC

From the dhclient manpage:

       -r     Release the current lease and stop the running  DHCP  client  as
              previously  recorded  in  the  PID file.  When shutdown via this
              method dhclient-script will be executed with the specific reason
              for calling the script set.  The client normally doesn't release
              the current lease as this is not required by the  DHCP  protocol
              but  some  cable ISPs require their clients to notify the server
              if they wish to release an assigned IP address.

Hope this helps!

  • For the second command (sudo dhclient eth0) I get this error: Failed to try-reload-or-restart systemd-resolved.service: Unit systemd-resolved.service is masked. It's actually because I use dnscrypt-proxy and I have to have systemd-resolved masked, otherwise it will interfere with it. Any other option? Thanks. – Shayan Aug 23 '19 at 17:18
  • 1
    @Shayan I really don't know about dnscrypt-proxy and I wouldn't know any commands to help about that. I guess you could try downing the eth0 port then bring it back up. sudo ifconfig eth0 down then sudo ifconfig eth0 up. Sorry for the late response. – Terrance Apr 23 '20 at 21:51

One way to accomplish this is to tell network-manager to briefly disconnect the device and the connecting it again:

nmcli device disconnect wlan0; nmcli device connect wlan0 

(replace wlan0 with the correct device name on your system)

  • So there's no equivalent to ipconfig /release /renew of Windows for Linux? But other than that, your answer works perfectly. – Shayan Aug 23 '19 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.