Occasionally, my Wi-Fi connection does no longer work for various reasons. Disabling and re-enabling Wi-Fi through the graphical interface of the network indicator does not resolve the problems in these cases.

How can I completely restart my Wi-Fi connection from the command-line without having to restart my machine (which fixes these problems)?


4 Answers 4


nmcli is very useful command-line utility for interacting with Network Manager. Use this command in Ubuntu 16.04 LTS

nmcli radio wifi off && sleep 5 && nmcli radio wifi on

For versions prior to 15.10 ( i.e. before transition to systemd ) the command would be slightly different:

nmcli nm wifi off && sleep 5 && nmcli nm wifi on

Good thing about it - this doesn't require root powers.

Restarting network manager itself is a good idea as well.

For 16.04 LTS:

sudo systemctl restart NetworkManager

and for 14.04 LTS:

sudo service network-manager restart

And if we really wanted to, we could even automate it with a script that will restart your wifi.

# replace wlan0 with your device name
# as given by ip addr or ifconfig
while true 
    # keep checking if we have ip address    
    wifi_info=$(ip -4 -o addr  show wlan0 )
    while [ -n "$wifi_info" ];
       wifi_info=$(ip -4 -o addr  show wlan0 )
       sleep 0.25

    # We get here only if IP address is lost
    # which means we're off-line
    # restart wifi 
    nmcli radio wifi off && sleep 5 && nmcli radio wifi on
  • 4
    .service is implied, so can be omitted sudo systemctl restart NetworkManager
    – Zanna
    Commented Aug 13, 2016 at 8:42
  • 1
    @Zanna TIL... I have been typing .service this whole time.
    – edwinksl
    Commented Aug 13, 2016 at 9:10
  • Worked like a charm for me.
    – Josh
    Commented Oct 14, 2017 at 7:44
  • Thanks, excellent. Why are there 2 different commands?
    – neverMind9
    Commented Apr 17, 2018 at 21:50
  • 1
    @TechLord Basically, it's because since the 15.04 version, Ubuntu has switched to systemd init system - the stuff that actually brings up basic services and daemons when you boot. The problem is that unlike older stuff, systemd tries to not just start stuff, but also manage the stuff. This lead to nmcli being rewritten to match with systemd. At least this is my understanding. Commented Apr 17, 2018 at 22:02

Two alternatives I'm thinking about follows,

First alternative, bring down/up the interface

ifconfig wlan0 down ## assumes your wlan is named wlan0
ifconfig wlan0 up

Second alternative, restart the entire network-manager. This assumes you have network-manager installed. If not, install it with the following cmd in your terminal sudo apt-get install network-manager.

sudo service network-manager restart

On Ubuntu 15.10 and 16.04 LTS you can use the systemd feature:

 systemctl restart NetworkManager.service

Use ifdown + interface name to disable network

ifdown IFACE

Use ifup + interface name to enable it

ifup IFACE

Replace IFACE with your device name as given by ifconfig

You must log in to answer this question.

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