How to prevent wifi sleep after suspend
Solution 1
There are two ways of enabling WiFi after sleep. The first is a common patch to Network Manager as you can see I've made by listing the file:
Turn off or enable power savings as illustrated below:
$ cat /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
[connection]
wifi.powersave = 3
# Slow sleep fix: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1670041
#wifi.powersave = 2
- Edit the Network Manager file shown above.
- Change
WiFi.powersave
from2
to3
(Enable power saving). - If it's already set to
3
try setting it to2
(Disable power saving). - After saving the file run
sudo systemctl restart NetworkManager
The second is a systemd
script which reloads the WiFi kernel module when resuming from suspend. It comes from this answer: Wifi available networks not showing up suddenly:
This script is written for iwlwifi` which is the common Intel driver name. If your's is different change that name below:
#!/bin/sh
# NAME: /lib/systemd/system-sleep/iwlwifi-reset
# DESC: Resets Intel WiFi which can be flakey after a long suspend.
# DATE: Apr 1, 2017. Modified August 30, 2017.
MYNAME=$0
restart_wifi() {
/usr/bin/logger $MYNAME 'restart_wifi BEGIN'
/sbin/modprobe -v -r iwldvm # This removes iwlwifi too
/sbin/modprobe -v iwlwifi # This starts iwldvm too
# systemctl restart NetworkManager.service
/usr/bin/logger 'systemctl restart NetworkManager.service (SUPPRESSED)'
/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
NOTE: Sometimes simply resetting network manager is all that is needed. In that case un-comment the line above by removing #
. Then comment out the two lines above it by putting #
at the beginning of those two lines.
You'll need to create this script, called iwlwifi-reset
, with sudo
powers and save it into the directory /lib/systemd/system-sleep
. Then mark it executable using:
chmod a+x /lib/systemd/system-sleep/iwlwifi-reset
Solution 2
First ceate a new script and make it executable.
sudo touch /usr/lib/pm-utils/sleep.d/wakewifi
sudo chmod a+x /usr/lib/pm-utils/sleep.d/wakewifi
Then edit the script
sudo nano /usr/lib/pm-utils/sleep.d/wakewifi
and make it look something like this.
#!/bin/sh
case "$1" in
resume)
nmcli radio wifi on
esac
to make sure that nmcli radio wifi on is the correct command, try to go into sleep mode, start the computer up and do
sudo nmcli radio wifi on
if your computer then connect to the correct wifi, then this might be a optional solution for you. your computer should auto-connect. to your saved wi-fi access point.
Solution 3
I think it is related to systemd. You can make a script that starts the wifi device after suspend. Just try to do so manually first.
Related videos on Youtube
Guerlando OCs
Updated on September 18, 2022Comments
-
Guerlando OCs over 1 year
Every time I open my notebook lid I have to wait a few seconds for wifi to reconnect. I remember that in Windows it was already connected. I need a way to prevent wifi from disconneting on suspend.
The closest answer I found was https://askubuntu.com/a/961460/613425 but it didn't work. I also tried the
iwconfig wlan0 poweroff
in the answer but it didn't work even before reboot.-
user68186 about 6 yearsSo, unlike the question you linked above, your WiFi is not unstable. It connects and works fine after you open the lid and wake up the laptop from sleep. You want WiFi to connect more quickly. What would happen when you move your laptop 20 miles while it was sleeping? Would it still remain connected?
-
Guerlando OCs about 6 years@user68186 it never remains connected, even in the same place after I reopen the lid. I have to wait for it to connect again.
-
user68186 about 6 yearsDo you mean it never remains connected while it sleeps? I once knew someone who used to talk while sleeping, but my laptop doesn't do that. I don't think what you want is possible unless you stop your laptop from sleeping altogether.
-
Sebastian Stark about 6 yearsWhat laptop model do you have?
-
Guerlando OCs about 6 years@user68186 but when I had windows it did exactly that, its wireless was connected right when I opened the lid
-
Guerlando OCs about 6 years@SebastianStark Razer Blade Stealth 2016 12.5". It had the desired behavior on windows
-
user68186 about 6 yearsTry the first answer from WiFi doesn't work after suspend after 16.04 upgrade
-
Fabby about 6 yearsWhat's the output to
iwconfig
? Please edit your question to provide the output there instead of here in the comments. -
elliottregan over 3 yearsI see there are some scripts that work, but I want to throw this out there. There's a good chance that Windows is simply displaying the last known network as if it were connected, but in reality, it's doing that same thing as Ubuntu is.
-
-
jherek almost 5 yearshad the same problem with Fedora 31 + XFCE (not with gnome shell), the first way solved it.
-
orschiro about 3 yearsDoes the systemd approach trigger while on sleep or after resuming from sleep? I think the original question looks for a solution while on sleep not after resuming from sleep.