I had a similar problem and none of the solutions I found fixed it completely. For me, it was taking up to 5 minutes after resuming from suspend before the WiFi would connect. I had initially tried editing the configuration in /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
, but I found that it didn't do anything. After some more digging, I found the solution on Let's FOSS - WiFi not working after Suspend in Ubuntu, where it triggers the network manager service to restart on resume, but it still took like an entire minute after the network manager service restarted.
But I noticed that restarting the Network Manager using sudo service network-manager restart
, caused it to connect within 30 seconds to a minute.
So, after playing around with the settings and doing more research, I came to the following solution.
SOLUTION
Open up terminal (CTRL+ALT+T) and enter sudo nano /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
, and edit it so its contents look like this:
[connection]
wifi.powersave = 1
Save the file by pressing CTRL+X, then press ENTER to save to the current file path.
Enter the following command to make a default-wifi-powersave-off.conf
file with the same contents as default-wifi-powersave-on.conf
sudo cp /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf \
/etc/NetworkManager/conf.d/default-wifi-powersave-off.conf
Create and edit a new script, /lib/systemd/system-sleep/wififix
, with the following command
sudo nano /lib/systemd/system-sleep/wififix
Add the following to wififix
:
#!/bin/sh
# command line input we're expecting:
# # wififix <pre|post> <suspend|hybrid-sleep>
set -e
if [ $2 = "suspend" ] || [ $2 = "hybrid-sleep" ]; then
case $1 in
pre)
true
;;
post)
# After 0.1 seconds, restart the network manager service
sleep 0.1 && service network-manager restart
;;
esac
fi
Save wififix
by pressing CRTL+X, then ENTER. Then make the file executable with the following command
sudo chmod +x /lib/systemd/system-sleep/wififix
Test the wififix
script by entering the command
sudo /lib/systemd/system-sleep/wififix post suspend
It should hang in the terminal for a split second, then you should see the WiFi status indicator disappear then quickly reappear and connect.
EXPLANATION
Just a disclaimer, I am a PHP developer who casually uses Ubuntu, not a Linux/Ubuntu expert.
The wififix
script in /lib/systemd/system-sleep/
is the main fix here. It forces the network manager service to restart within 0.1 seconds after resuming from suspend. This always got me connected faster than when I let the system reconnect/re-enable on its own.
The reason for creating the /etc/NetworkManager/conf.d/default-wifi-powersave-*.conf
files, was to make sure that no behavior is employed when entering and exiting suspend (see here). I found that this way the WiFi gets up and running faster after the network manager restarts because it does not try to change any setting on your wireless card or anywhere else (which could cause issues depending on other .conf
settings files in /etc/NetworkManager/
). Without those scripts, it was still taking like a minute or so to connect to WiFi, but with them it now only takes a matter of seconds and I'm usually connected before I finish entering my password!