165

This particular version of the "doesn't work after suspend" came after upgrading to 16.04. It seems that the upgrade includes a Wicd applet (added to Metacity Classic Gnome task bar alongside regular network icon), but doesn't seem to work after a suspend. A sudo service network-manager restart duplicates this problem. It takes a complete reboot to get Wifi going again. Any ideas why?

147pm
  • 2,165
  • 6
    Did you file a bug at launchpad for the problem ??? – apos May 16 '16 at 14:04
  • 3
    https://bugs.launchpad.net/ubuntu/+source/wpasupplicant/+bug/1556357 – Alberto Salvia Novella Jun 20 '16 at 17:36
  • Looks like this problem has been around since Ubuntu 14. – Dan Dascalescu Sep 09 '16 at 03:41
  • This never happened under 14.04 LTS for me. The upgrade to 16.04 LTS is so great I'll keep it, but it keeps forgetting my WiFi password. The service is clearly running; just that it forgets the password and doesn't connect. I posted this: https://askubuntu.com/questions/934958/how-to-make-ubuntu-16-04-lts-remember-my-wifi-password-through-a-shutdown - and I do not want to deal with blacklisting or anything strange. – SDsolar Jul 11 '17 at 03:57
  • ... And the problem is still there in Ubuntu 20. I'm kinda fed up at this point. – Dan Dascalescu Jun 19 '20 at 19:39

12 Answers12

187

16.04 runs on systemd. Try the following:

sudo systemctl restart network-manager.service

If this works, you can create a script to automate it.

Open a terminal and type the following:

sudo nano /etc/systemd/system/wifi-resume.service Now paste the script in there with a right click. Exit with CTRL + X and press Y to save. Now to activate it: sudo systemctl enable wifi-resume.service

Script:

#/etc/systemd/system/wifi-resume.service
#sudo systemctl enable wifi-resume.service
[Unit]
Description=Restart networkmanager at resume
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart network-manager.service

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

Hope this helps. It works on my laptop.

Joakim Koed
  • 2,792
  • 3
  • 17
  • 29
  • Yes, that correction didn't error out, but it's still not working. Again, I have two icons in my panel, side-by-side, one for the usual network, one is wicd. I didn't have wicd there before. Are they clashing. BTW, my KDE Plasma doesn't seem to have this problem. – 147pm Apr 23 '16 at 16:14
  • 2
    Have you tried to simply uninstall wicd? – Joakim Koed Apr 23 '16 at 16:41
  • Uninstalled, but problem persists. Now I have just the original network icon, but still no connection (doesn't see wifi hotspots) possibilities after coming back from suspend. – 147pm Apr 23 '16 at 17:04
  • Did you create a /home partition, if so, I would reinstall, instead of upgrade, to be honest. Not really a solution, but often fixes these things. – Joakim Koed Apr 23 '16 at 17:39
  • 6
    I would say don't bother reinstalling for this. I did a clean install and I'm running into this issue on 16.04. Never had a problem with 14.04. – Michael Martin-Smucker May 04 '16 at 00:25
  • @JoakimKoed please edit your answer to use the lower-case version of the command at the very beginning – jerivas May 04 '16 at 03:03
  • the command: sudo systemctl restart network-manager.service works but not the script. – tokam May 08 '16 at 13:56
  • @tokam the script is running after each time you resume from sleep. That is when I had issues. Are you running 16.04? – Joakim Koed May 08 '16 at 14:00
  • Yes it appears to be working now fine – tokam May 15 '16 at 16:26
  • 3
    Sometimes it works and sometimes not :( – tokam May 17 '16 at 18:52
  • @tokam sorry it's not working for you all the time. It works perfect for me. Lets hope they get these nasty bugs fixed soon. – Joakim Koed May 17 '16 at 19:48
  • @JoseCarlosRamosCarmenates what is not working? The script or the first command? – Joakim Koed May 19 '16 at 18:04
  • @JoakimKoed None of the solutions work to me., thanks in advances. I use Kubuntu 16.04 - asus republic of gamers. – Jose Carlos Ramos Carmenates May 19 '16 at 18:33
  • I assume you mean neither things? Anyway, this will only work IF you have some problems after suspend. If it's not working at all maybe do a post yourself and ask for help.. Remember to provide logs, your wifi card etc. – Joakim Koed May 19 '16 at 18:35
  • Sometimes your command fixes the issue, sometimes not. Also the script does not fix the issue sometimes. My main problem is, that I am online, but this information is not spread among NM-Applet and Evolution. So I can not download E-Mails because Evolution does not even try when it thinks that the system is offline. Now after running your command a restart of evolution helped. – tokam May 24 '16 at 10:06
  • @takan: seems you have a deeper problem :( – Joakim Koed May 26 '16 at 13:14
  • which one? how to find that out? I have an own thread for this, which was guided to the one here: http://askubuntu.com/questions/767878/networkmanager-does-not-know-that-i-am-online-after-resuming-from-hibernate?noredirect=1#comment1147389_767878 – tokam May 27 '16 at 20:02
  • For me only running /etc/init.d/network-manager restart fix the problem, should I put it in a script like you did? (the systemctl command doesn't work for me) – elichai2 Jun 10 '16 at 07:19
  • @elichai2 Then you are not running 16.04 or anything with systemd. The script is really made for systemd. See something like this: http://askubuntu.com/questions/452826/wireless-networking-not-working-after-resume-in-ubuntu-14-04 – Joakim Koed Jun 10 '16 at 07:23
  • Do you think some part of the Ubuntu network stack is still using the upstart command? Perhaps there is another place in the init system that executes the old command and replacing it with the systemd equivalent can fix the problem at the source rather than stemming another Unit on the end. This would be good for a bug report on Launchpad if so and it could affect other systems. – mikeymop Sep 02 '16 at 00:40
  • 1
    @mikeymop I have been thinking this as well. I know some parts of the system is still using upstart, so that might trigger something. Since 16.10 is full systemd and does not have the error, you might be correct. – Joakim Koed Sep 02 '16 at 09:19
  • I've been testing a variation of this for the past week, and it restarts the network flawlessly. No more Wi-Fi problems. – Dan Dascalescu Sep 15 '16 at 07:07
  • @JoakimKoed This works perfectly for me. Is there a way to temporarily disable this for a period of time to see if it is still necessary? What is the proper way to reverse this work around? – Dennis Oct 27 '16 at 15:17
  • @Dennis sudo systemctl disable wifi-resume.service – Joakim Koed Oct 27 '16 at 15:19
  • This worked wonders for me. I'm running Ubuntu 16.04 on an MSI GP60 and after resuming from suspension it would connect to my wifi but it didn't show the wifi channel I was connected to or any available wifi channels. – Cornelius Nov 06 '16 at 22:08
  • 1
    How can I remove this, this won't work on my system – an offer can't refuse Dec 02 '16 at 05:01
  • The script in this answer seems to work just fine for me. I've used it on two X1 Carbons, one 2nd generation and one 4th, and it has helped a great deal. Thanks! – jerome Dec 28 '16 at 02:57
  • Also try NetworkManager.service if network-manager.service fails. – timelmer Jan 24 '17 at 02:55
  • Tried only resuming at the command line. It works. Will check if the issue ever shows up again. – sancho.s ReinstateMonicaCellio Mar 07 '17 at 09:06
  • 1
    Script is not working for me. "Wifi Disabled" is shown in my networks, I have realtek RTL8723be driver – Arshad Mar 13 '17 at 10:16
  • This has worked on Ubuntu 16.10 with my Dell XPS 15 9550 (it has some DNS problems after suspend/resume, https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1673796 ) Thanks! – morhook Mar 22 '17 at 18:37
  • this has worked on Ubuntu 16.04.2(Acer E15) – Parnab Sanyal Apr 11 '17 at 16:24
  • It doesn't seem to work consistent on my XPS 9550 Ubuntu 16.04. Manual restart with the same command works like a charm though. I will add asleep command similar to a suggestion in another post and test it for a while. Another problem that was also mentioned here is that a network applet disappears from the panel and I don't know how to return it. It would be really nice to have(restart unity-panel-service doesn't help). – yuranos May 10 '17 at 04:04
  • Thanks for making a script for us. But it doesnt run on resume for me. If i go and run "sudo systemctl restart network-manager.service" manually, it fixes the problem however. – Terje Nesthus Jul 16 '17 at 15:50
  • 1
    The command "sudo systemctl restart network-manager.service" always works for me, but the script does not work. I am using ubuntu 16.04. – Jonathan Lindgren Sep 02 '17 at 08:15
27

@147pm Did you ever get this working?

I found I had a quite similar problem, though I am on Kubuntu 16.10 (KDE-based, not Gnome), and with an HP ProBook laptop. And, unlike yourself, it wasn't my Wifi which died after suspend/wakeup, but my ethernet port. Still, I wonder if they are related.

I also do see that you do not have the problem under KDE. But I would be interested to know if the solution below does help under Gnome, as the solution is not based upon window manager, desktop environment or applets.

First, just to confirm that restarting the network manager service..

$ sudo systemctl restart network-manager.service

did not work for me.

However, I did find an answer that worked, thanks to buzhidao's question and info at can't connect to internet after suspend and GAD3R's comment there.

Using their info, I found that first researching which ethernet hardware and driver/module I am running, and then removing and reloading that module, did work for me (though it did not for buzhidao):

Wifi:

$ lspci -knn | grep Net -A2

Ethernet:

$ lspci -knn | grep Ether -A2

The second of these (ethernet) was what I used, and I found:

03:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller [10ec:8168] (rev 0c)
        Subsystem: Hewlett-Packard Company RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller [103c:1944]
        Kernel driver in use: r8169
        Kernel modules: r8169

so i reloaded the 'r8169' driver:

$ sudo rmmod r8169 && sudo modprobe r8169

and voila! This worked. My ethernet port / connection came back alive (after suspend/wakeup) without having to reboot.

(I also did NOT have a Realtek wifi device, but a Qualcomm Atheros (mod: ath9k) which perhaps explains why wifi continued to work for me after wake-from-suspend.)

As you can see from my comment on that other post, I wondered whether the problem is the common element between Buzhidao and myself: Realtek Semiconductor devices. Even though they use different modules, they might share some common code? Or even be treated differently by the newer kernel code now in some way?

Do you yourself have a Realtek-based wifi device? (using lspci above)? Do you have any luck re-installing the module (rmmod/modprobe above)?

Anyway, just a shot in the dark. If you have found an eventual answer for yourself, please let us know! Thx.

Androclus
  • 471
  • 1
    I also have a RTL8111/8168/8411 ethernet and sudo rmmod r8169 && sudo modprobe r8169 solved the problem. – lenooh Jun 24 '18 at 13:25
  • Same issue on Debian 9 with KDE. Reinstalling as above fixed it. Thanks a ton. – sumitkm Aug 02 '18 at 06:16
  • My computer* too has a RTL8111/8168/8411 ethernet device and sudo rmmod r8169 && sudo modprobe r81691 finally fixed the issue for me. Didn't have this problem before kernel version 4.16.

    (*Debian 10 with GNOME, Kernel 4.16, and proprietary firmware from Realtek)

    – ossbuntu Aug 08 '18 at 12:54
  • worked for me archlinux with ath10k_pci –  Jul 06 '19 at 11:49
  • re-insert kern module fixed for me on xub 19.10. Interestingly, this issue started only recently, didn't happen on 19.04 or older for me. I'm on t420. – Victor Sorokin Apr 05 '20 at 10:02
  • Reloading the module also worked for my ath10k_pci wifi adapter. It had worked smoothly until some update. I'm on Ubuntu 20.04, kernel 5.4.0-37-generic #41 – laurent Jun 15 '20 at 13:12
  • Had the same issue and so needed this! Different driver on Debian Buster, same fix. – therightstuff Jul 27 '20 at 16:54
  • This problem persists into U 20 and this solution worked for me (the others did NOT). Thanks! – Sean Lawton Oct 20 '20 at 13:24
  • same here with a macbook pro early 2015 and ubuntu 19, I didn't want to install a different broadcom driver because honestly it mostly works fine, but this was the fix I needed for waking up from a long sleep (maybe hibernation?) – Eli Albért Dec 01 '20 at 19:00
  • Thanks! On my Ubuntu 20.10 it was rtw88_8822ce that had to be reloaded (Network controller: Realtek RTL8822CE 802.11ac PCIe wireless network adapter). – 4LegsDrivenCat Jan 02 '21 at 15:36
  • Going to save this, so useful!! – fitojb Jun 12 '21 at 07:25
  • Thank You very much Was trying many other solutions for hours finally yours worked on my Ubuntu 20.04 :) – Divyessh Jun 24 '21 at 11:38
  • Finally it works. Tried many other solutions with no luck. Thanks! – callOfCode Nov 15 '21 at 20:38
6

To auto-restart NetworkManager after resume in an environment without sudo access, create a script in /etc/pm/sleep.d (any name), set the executable bit via chmod +x, and insert the following content:

case "${1}" in
    resume|thaw)
        # systemctl restart network-manager.service
        service NetworkManager restart
;;
esac

For me, the service line worked, but systemctl may work better for you.

Source: https://askubuntu.com/a/92235/30266.

krlmlr
  • 3,337
  • 2
    The service NetworkManager restart worked for me, but the placement of the script did not (on 16.04). I had to move the script to /lib/systemd/system-sleep/script-name-here. In this case the first argument to the script is [pre | post], so I had to change the case statement to case "${1}" in ... post) .... I also wrapped the inner statement in case "${2}" in ... suspend) .... – Chester Nov 16 '16 at 13:28
  • 1
    Should be /lib/systemd/system-sleep/ for 15.04+ – qwr Feb 01 '17 at 06:17
3

For me it seems to be random, but sometimes the wifi just disconnects if I'm connected, or doesn't show networks if I'm not. Sometimes putting my laptop into sleep mode seems to trigger it, but not always.

Some combination of these usually gets it going again without rebooting:

  • sudo iwlist $(ifconfig | grep -Po '^w\w+') scan
  • sudo service network-manager stop; sleep 5; sudo service network-manager start
    • Simply calling restart here never seems to work for me. It looks like it tries to start it up before it's finished shutting it down, hence I have more luck pausing between stop and start.
  • Turn off wifi in UI; wait a few seconds; turn it back on

None of those seems to consistently work, but I listed them in order of most-likely-to-succeed first.

redbmk
  • 213
2

Run these commands one by one in the terminal.

1.sudo nano /lib/systemd/system-sleep/wififix
2. Paste the below code and save it.

#!/bin/sh
set -e
if [ "$2" = "suspend" ] || [ "$2" = "hybrid-sleep" ]; then
     case "$1" in
             pre) true ;;
             post) sleep 1 && service network-manager restart ;;
       esac
fi
  1. sudo chmod +x /lib/systemd/system-sleep/wififix

Tested on Ubuntu 20.04. It works on other Mint and Elementary versions as well.

I got the solution from here.

karel
  • 114,770
MC Naveen
  • 317
2

Working method on Ubuntu 16.04:

Create the service: sudo nano /lib/systemd/system/wifi-resume.service

The service is calling the program from:
/etc/init.d/network-manager

Paste the code:

#/lib/systemd/system/wifi-resume.service
#sudo systemctl enable wifi-resume.service
[Unit]
Description=Restart network-manager at resume
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target 

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart network-manager

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

Then enable the service:

sudo systemctl enable /lib/systemd/system/wifi-resume.service

This creates the symlinks into the indicated [Install] directories of /etc/systemd/system and activates the service

Afterwards you can check the status with: systemctl status wifi-resume.service

Demon
  • 818
1

I had the same problem with bluetooth: After suspend my bluetooth mouse did not work. So I derived the solution from above:

sudo nano /etc/systemd/system/bluetooth-resume.service

enabled the new service

sudo systemctl enable bluetooth-resume.service

and edited the service

#/etc/systemd/system/bluetooth-resume.service
#sudo systemctl enable bluetooth-resume.service
[Unit]
Description=Restart bluethooth at resume
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart bluetooth.service

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

I also tried to edit ...

sudo nano /etc/bluetooth/main.conf

and changed

AutoEnable=true

BUT this did NOT work for the "resume problem" and had no inmpact on new bluetooth devices anyhow!

apos
  • 529
1

I had the same issue on my laptop Dell Inspiron 15R with Ubuntu 16.04. For me worked the script reported on the second reply.

After having installed the script I tried the suspension with the command in the upper right menu and even closing the lip, solving the problem.

I have to say that the problem was alternating in its behaviour (that is, sometimes it worked before installing the script).

0

I had the same issue connecting back to my home wifi after suspend. Tried the various other suggested answers which would occasionally work but not always.

Eventually the following fix allowed for consistently connecting to the wifi:

1) Edit this file:

sudo vim /etc/NetworkManager/NetworkManager.conf

2) By adding this to it:

[device]
wifi.scan-rand-mac-address=no
Ray
  • 176
0

Now probably simple

sudo apt update
sudo apt upgrade

should work.

In my case among upgraded packages there was bcmwl-kernel-source (6.30.223.271+bdcom-0ubuntu1~1.3) and after this update wifi works again.

Daniel
  • 387
0

I had the same problem on Ubuntu 20.04. I tried the solutions above which didn't work for my intel 6235 adapter.

Random websearches instead led me to the solution:

sudo modprobe -r iwlwifi
sudo modprobe iwlwifi
sudo systemctl restart NetworkManager

Which resolves the problem until next suspend.

Simon
  • 159
0

For me the solution was to run

nmcli nm sleep false

in a terminal

tigerjack
  • 2,575
  • 7
  • 25
  • 38