I'm posting here as having troubles with the wifi after suspend.

I recently bought a new pcie wifi card (TP-LINK TL-WN881N), and it all works great. Unfortunately, it seems things turn bad when I put my computer to sleep, as the wifi doesn't work properly after waking up.

In face, the problem is weird. It does connect to the wifi network, connection is showed in nm-applet, connection seems alright in ifconfig, routes are fine, but it seems the drivers gets in a buggy mode where I cannot even ping (or reach in anyway) my gateway or any other location.

I tried different fixes, like the one here Wifi doesn't work after suspend after 16.04 upgrade or here Wireless networking not working after resume in Ubuntu 14.04 and none of them worked. The weirdest thing is, if I try to manually restart the network-manager service, things don't get solved and instead I even get troubles listing the wifi networks. A reboot seems like the only way to solve the problem so far.

Here are some details about my card and driver:

$sudo lshw -class network
  *-network               
       description: Wireless interface
       product: RTL8192EE PCIe Wireless Network Adapter
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0
       bus info: pci@0000:02:00.0
       logical name: wlp2s0
       version: 00
       serial: 30:b4:9e:72:08:78
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless
       configuration: broadcast=yes driver=rtl8192ee driverversion=4.10.0-32-generic firmware=N/A ip=192.168.2.2 latency=0 link=yes multicast=yes wireless=IEEE 802.11
       resources: irq:127 ioport:d000(size=256) memory:f7100000-f7103fff

Thanks!

edit:

Solved! Thanks @WinEunuuchs2Unix, it seems that by applying a similar method than the one described here WiFi signal icon switches to Ethernet icon (up down arrows) after Suspend?, I managed to solve the problem.

The conditions were not exactly the same, and I had to adapt the solution. Basically, restarting network-manager doesn't fix the problem, but unloading the reloading the kernel module worked! So here is how I adapted the script:

#!/bin/sh                                                                                     

# NAME: /lib/systemd/system-sleep/wifi-reset                                                  
# DESC: Resets Realtek WiFi after a long suspend.                                             
# DATE: Aug 25, 2017. Modified Aug 25, 2017.                                                  

MYNAME=$0                                                                                     

DRIVER=rtl8192ee                                                                              

restart_wifi() {                                                                              
    /usr/bin/logger $MYNAME 'restart_wifi BEGIN'                                              
    /sbin/modprobe -v -r $DRIVER # This removes the driver                                    
    /sbin/modprobe -v $DRIVER   # This starts the driver                                      
    #systemctl restart NetworkManager.service # network manager restart disabled as not needed
    /usr/bin/logger $MYNAME 'restart_wifi END'                                                
}                                                                                             

/usr/bin/logger $MYNAME 'case=[' ${1}' ]'                                                     
case "${1}/${2}" in                                                                           
    hibernate|suspend|pre*)                                                                   
    ;;                                                                                        
    resume|thaw|post*)                                                                        
        restart_wifi;;                                                                        
esac                                                                                          

It works perfectly now :)

Thanks guys!

Solved! Thanks @WinEunuuchs2Unix, it seems that by applying a similar method than the one described here WiFi signal icon switches to Ethernet icon (up down arrows) after Suspend?, I managed to solve the problem.

The conditions were not exactly the same, and I had to adapt the solution. Basically, restarting network-manager doesn't fix the problem, but unloading the reloading the kernel module worked! So here is how I adapted the script:

#!/bin/sh                                                                                     

# NAME: /lib/systemd/system-sleep/wifi-reset                                                  
# DESC: Resets Realtek WiFi after a long suspend.                                             
# DATE: Aug 25, 2017. Modified Aug 25, 2017.                                                  

MYNAME=$0                                                                                     

DRIVER=rtl8192ee                                                                              

restart_wifi() {                                                                              
    /usr/bin/logger $MYNAME 'restart_wifi BEGIN'                                              
    /sbin/modprobe -v -r $DRIVER # This removes the driver                                    
    /sbin/modprobe -v $DRIVER   # This starts the driver                                      
    #systemctl restart NetworkManager.service # network manager restart disabled as not needed
    /usr/bin/logger $MYNAME 'restart_wifi END'                                                
}                                                                                             

/usr/bin/logger $MYNAME 'case=[' ${1}' ]'                                                     
case "${1}/${2}" in                                                                           
    hibernate|suspend|pre*)                                                                   
    ;;                                                                                        
    resume|thaw|post*)                                                                        
        restart_wifi;;                                                                        
esac                                                                                          

It works perfectly now :)

Thanks guys!

I had a similar issue, but with a few differences though.

My laptop is a Lenovo ThinkPad T470s running Ubuntu 16.04.4 LTS (xenial).

After suspending and resuming, I had the following behavior:

  • the network manager would restart, and the list of wifi networks would be ok,
  • it would not make any difference whether the PC had been suspended for a short or long time,
  • it would actually reconnect to the wifi after resume,
  • I could successfully ping the PCs on the LAN,
  • I could not ping anything outside the LAN, and could not connect to the Internet.
  • (very strange) after having restarted the drive manually once (see fix below) this issue would have gone. I could suspend and resume and the wifi would work without having to restart the driver a second time. In order to reproduce the issue, I had to reboot, and suspend again.

Restarting the network manager (sudo systemctl restart network-manager.service) would not fix the issue. Stopping it, waiting for some time, and starting it again would not fix it either.

Manual fix

To fix manually, I had to:

  • determine my wifi driver:

    $ sudo lshw -C network
      *-network
           description: Wireless interface
           product: Intel Corporation
           vendor: Intel Corporation
           physical id: 0
           bus info: pci@0000:3a:00.0
           logical name: wlp58s0
           version: 78
           serial: 00:e1:8c:dc:8c:7d
           width: 64 bits
           clock: 33MHz
           capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless
           configuration: broadcast=yes driver=iwlwifi driverversion=4.13.0-43-generic firmware=31.560484.0 ip=192.168.0.9 latency=0 link=yes multicast=yes wireless=IEEE 802.11
           resources: irq:128 memory:ec100000-ec101fff
    
  • restart the driver:

    $ sudo /sbin/modprobe -r iwlwifi
    $ sudo /sbin/modprobe iwlwifi
    

Automatic fix

To automatically restart the driver after system resume, I did somethings similar to

WiFi signal icon switches to Ethernet icon (up down arrows) after Suspend?

that is, I created the following script iwlwifi-reset in /lib/systemd/system-sleep/, and made it executable.

#!/bin/sh

# NAME: /lib/systemd/system-sleep/iwlwifi-reset
# DESC: Resets Intel WiFi after suspend.
# DATE: Jun 3, 2018.

MYNAME=$0

restart_wifi() {
    /usr/bin/logger $MYNAME 'restart_wifi BEGIN'
    /sbin/modprobe -r iwlwifi
    /sbin/modprobe iwlwifi
    /usr/bin/logger $MYNAME 'restart_wifi END'
}

/usr/bin/logger $MYNAME 'case=[' ${1}' ]'
case "${1}/${2}" in
    hibernate|suspend|pre*)
        ;;
    resume|thaw|post*)
        restart_wifi;;
esac

In Ubuntu 18.04, to get the script to be called upon system resume, I had to do the following additional steps (I'm using an old Edimax USB WiFi adaptor, so I named the /lib/systemd/system-sleep/ script edimax_wifi_wakeup):

  • Create a "service" file: sudo vi /etc/systemd/system/sleep-resume.service
  • Its contents:

    [Unit]
    Description=Edimax USB WiFi system suspend/resume handling
    Before=sleep.target
    StopWhenUnneeded=yes
    
    [Service]
    Type=simple
    RemainAfterExit=yes
    ExecStart=-/lib/systemd/system-sleep/edimax_wifi_wakeup suspend
    ExecStop=-/lib/systemd/system-sleep/edimax_wifi_wakeup resume
    
    [Install]
    WantedBy=sleep.target
    
  • Enable the service by sudo systemctl enable sleep-resume

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.