I think I do not have problem with hardware. Sometimes the WiFi connection simply disconnects, apparently. So this is not necessarily the same as this case, I might not need to reload any modules.

But how to just restart wlan0? I tried restart network-manager, but this seems to leave wlan0 alone.

You just need to restart Network Manager:

sudo service network-manager restart
  • 7
    it works for me after my wifi get stuck. – Felipe Mar 28 '15 at 14:12
  • 4
    On newer versions of Ubuntu, it might (depending on whether the system is using systemd) be better to use sudo systemctl restart NetworkManager. – TSJNachos117 Dec 11 '16 at 1:47
  • Works much better than a system reboot! – Ben Winding Dec 26 '16 at 14:15
  • 1
    Works for me running 16.04 on a ThinkPad t420. Is there any documented reason why we need to do this? – mbigras Feb 28 '17 at 3:30
  • Haha, yes but on Ubuntu GNOME 17.04 sudo doesn't work when the network becomes disabled. Quite the catch 22. – grofte Jun 30 '17 at 13:56

Try this:

sudo ifconfig wlan0 down
sudo ifconfig wlan0 up
  • assuming these interfaces are defined in the /etc/network/interfaces file. Else, you might get the infamous Unknown interface error – asgs Oct 13 at 15:38

These don't need root, in case you are scripting:

nmcli networking off 
nmcli networking on

For more do: man nmcli

EDIT:

As these guys are saying in the comments, for WI-FI only:

nmcli radio wifi off
nmcli radio wifi on
  • 3
    Nice! (+1) Just to make it more specific to the wifi connection, one can use: nmcli radio wifi off followed by nmcli radio wifi on – n1k31t4 Oct 6 '17 at 23:56
  • 1
    @n1k31t4 would you mind editing this answer, please? this is exactly what the OP needed and probably a lot of other people looking at this post. – asgs Oct 13 at 15:40

You could try killing the power to your device. Assuming you are unable/unwilling to physically disconnect the device, you should run (as root): iwconfig wlan0 txpower off. I would then wait 10-15 seconds to make sure whatever hardware issue has caused the problem has been stopped, then: iwconfig wlan0 txpower auto.

Or, you can simply run rfkill and block/unblock your device. To do so, run rfkill block wifi, followed by rfkill unblock wifi. This second option should be faster, since you only need to wait 2-3 seconds between commands, as opposed to 10-15 seconds. In fact, on my machine, I don't need to wait at all, although I suspect this depends on your WiFi hardware. This option can also be done as a regular user, no root needed.

You can also restart NetworkManager. If you use systemctl as your init system (as is the case with newer versions of Ubuntu), you can use systemctl restart NetworkManager. Otherwise, you can use sudo initctl restart network-manager. If you don't know what init system you use, try both commands and see what works.

  • This is rather a software issue than an hardware issue, since is was working fine before Ubuntu16.04 and multiple users suffer from the same with the same Ubuntu version. – Hibou57 Sep 30 '17 at 10:57

Created a script based on prior link advice with some mixing & matching of prior links. This works for me running under Mint Linux 17.3.

The file below does not require root access. It also only restarts wifi only if it is already down. Now I just need to add this script to a cron job to check my wifi connection every 15 minutes or so.

#!/bin/bash

wlan=$(/sbin/ifconfig wlan0 | grep inet\ addr | wc -l)
if [ $wlan -eq 0 ]; then
nmcli nm wifi on
else
echo "interface is up"
fi

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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