Wifi doesn't work after suspend after 16.04 upgrade

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?


Solution 1:

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.

Solution 2:

@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.

Solution 3:

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.

Solution 4:

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.

Solution 5:

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