Is there a way to restart the Network manager every time I check the "Enable Wi-fi" from the applet's dropdown menu?
3 Answers
I know this is an old thread, but on my older laptop I had a pretty crappy WiFi card which had a tendency to disconnect from the WiFi if there was a lot of load (e.g., downloading large files, etc.).
I ended up creating a simple script to check if my internet was still connected, and if it wasn't, then restart the network manager.
#!/bin/bash
ping -c 1 8.8.8.8
received=$?
echo $received
if [[ $received -ne 0 ]] ; then
service network-manager restart
fi
I created a root cronjob with sudo crontab -e
, and set it such that every minute (you can do it more less frequently, but the script is a simple ping so it isn't resource intensive) it would run the script.
So, if my WiFi did go out for some reason, it would only ever be out for about a minute at a time, tops. If you're unfamiliar with cron
, I recommend reading this
-
1Welcome to Ask Ubuntu and although it's an old thread, it's better than the other answers, so +1 for that. OTOH, if you want to point people to cron help, better send them on this site, so I've edited that. – Fabby Jun 12 '18 at 17:43
-
I had to write
/usr/sbin/service
instead ofservice
. Also, the crontab expression you're looking for is*/1 * * * * /home/your_user/restart_network_if_needed.sh
assuming that's where you copy-pasted the above script – ihadanny Dec 17 '18 at 06:05
press alt+f2 to get a run dialog
in the run dialog type:
systemctl network-manager restart
You should then provide your password when prompted.
-
Thank you for your answer. Is there a way, however, to automate the process, for example through a script? – Oct 08 '16 at 04:01
in a terminal (Ctrl-Alt-t), sudo systemctl restart NetworkManager
should do the trick.
However, you can split it into stop
and start
command
sudo systemctl stop NetworkManager
sudo systemctl start NetworkManager

- 9,231
sudo
. Why exactly do you need to restart it ? What's the underlying issue ? – Sergiy Kolodyazhnyy Oct 06 '16 at 01:07