The wireless network on my dell laptop goes away many a times when resuming from 'suspend'. Once I run 'sudo service network-manager restart', it starts to work.
I was wondering if there was a way where I could restart the network while resuming from suspend and only if the wireless network was not up! What would be the best way to be able to restart network without having to enter a password?
I don't want to manually do it by going over to network icon and then taking some mouse actions. I did rather have a command which I could set up as a shortcut. I tried creating a bash executable with content 'service network-manager restart' and setting setuid on the executable as well as giving root the ownership of it but that didn't work.
I have Ubuntu 14.04 Trusty OS.
You can make a change to
sudoers
to allow your user account to execute the necessary commands without password.Warning: Be sure to not delete anything from
sudoers
without exactly knowing what its for! You could potentially loose all admin privileges.sudo visudo
In the section headed "Cmnd alias specification" add
NETWORK
is just an alias for a group of commands. Give it a different name if you prefer!At the end of the file, append the statement
where you substitute your user account for
user_name
. Also replaceNETWORK
with whatever name you've given the alias. One could also do without the alias and simply replace it by the command, but I prefer it this way. I find it keeps things more organized.Safe the file and exit the editor. Check with
sudo -l
that you are now indeed allowed to issue the command.You still need to prepend the command with
sudo
, but you won't be prompted for a password anymore.Another possibility is to use the command line interface of Network Manager (it's not so "strong" as restarting the daemon, but it worked for me). In this case, the operation is exactly the same as if you interact with the applet, so you do not need any privilege.
To restart the wifi interface, use this code:
I had similar problems with the network dropping (it was a faulty router in my case), so I used this script added to the startup jobs:
it checks the connection every minute and if it does not work, it restarts the wifi.
If this is not sufficient, you probably have to use stronger weapons, like starting/stopping Network Manager. Even that sometime fails on me, and I have to resort to unload (
sudo rmmod
) and then reload (sudo modprobe
) the wifi card driver module.You should be able to add something similar to this:
to your /etc/sudoers file and be able to restart network-manager with your script.
I finally ended up writing the script /etc/pm/sleep.d/0000_custom:
Thanks to @RMano and @Nephente for their answers.
On Ubuntu MATE 20.10 I'm using:
Here is my "one-liner" to monitor and restart networking after 6 consecutive router pings failed (sometime connection restores on itself after some failed attemts):
Note: The
192.168.88.1
is the IP address of my router. Modify for your needs (8.8.8.8
should be enough if you don't know router IP address).Note: To figure out your routers IP address see How to show (just) the IP address of my router? (the "one-line" script can be upgraded using this to automatically get te routers address)