Simple way to restart Linux networking

Q I have a PC running SUSE 10.0 that is used by everyone in my household for browsing, email, TV and playing movies and music. None of my family has any Linux user knowledge and this has caused some hassles when I am not around. The PC is connected to broadband via Wi-Fi, which works well almost all of the time. The only problem I have is that when my ISP has problems and drops me off (usually in the early hours of a Saturday) the wireless router needs to be restarted. This requires a restart of the networking on the PC - it's a simple process for me, but I cannot get my non techie family members to understand firstly why a terminal session is needed and secondly what all that root rubbish is about! They just want an icon to initiate the network restart. Can you help?

A If your family don't understand why a root password is needed, you definitely should not be giving it to them! This is exactly the sort of situation that calls for sudo. You need to create a script that contains the sequence of commands needed to bring your connection back up and save it somewhere safe, say /usr/local/bin/restartnetwork. Make sure root owns this script and only root can edit it with

chown root: /usr/local/bin/restartnetwork
chmod 755 /usr/local/bin/restartnetwork

Add this to your /etc/sudoers file so that anyone in your users group can execute it without a password, like so:

%users ALL = NOPASSWD: /usr/local/bin/restartnetwork

This allows all members of the users group to run your script without having a password. If you change NOPASSWD to PASSWD, the user will have to provide their own password. You could specify individual users instead of a group by using a comma-separated list, such as

ma,pa,johnboy ALL = NOPASSWD: /usr/local/bin/restartnetwork

Now any authorised user can run the script with

sudo restartnetwork

The full path is not needed here if /usr/local/bin is in $PATH, but it must be given in /etc/sudoers. Once you have your script, you can drop it on to the desktop or the panel to create an icon or button and any of your users can reset the network with a mouse click. Because sudo is executing the script as root, all of the commands you put in it will be run as root when called from the script, without giving your family permission to run those commands (or any others) directly. I use this method to add a button to my laptop's panel to start my wireless network - not because I don't know the root password, but because I am lazy and one click is less effort than typing my password.

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar