I usually click on the connection item in the connections drop-down menu in the upper right corner of the screen to activate my Internet connection. Is there a way to set a custom keyboard shortcut to get the same result? Hopefully a single command that I could insert among my other Custom keyboard shortcuts in System Settings > Keyboard.

Thank you very much, have a good day.

P.S.: the matter continues here: How to set a single shortcut to switch an Internet connection on and off .

  • Doesn't it connect automatically to the internet?
    – edwin
    Jul 13 '13 at 15:43
  • No, I prefer to turn the connection on when I need it and then to turn it off.
    – Andrew
    Jul 13 '13 at 19:10

Please read the whole thing before modifying anything. Ask away if you have doubts with some step.

Approach 1: Using nmcli

Open Keyboard and add a custom shortcut. For the command type nmcli nm enable true, that will activate the Network Manager (if your network is set to Automatic it should connect immediately). If you want a shortcut for disconnecting, the command would be nmcli nm enable false.

For more information about nmcli and other ways to accomplish what you want, read man nmcli.

Approach 2: Using /etc/network/interfaces

If you'd rather activating/configuring your internet connection manually, you can skip Network Manager and configure the file /etc/network/interfaces to your needs.

First disconnect from the internet and disable Network Manager:

sudo stop network-manager
echo "manual" | sudo tee /etc/init/network-manager.override

Open /etc/network/interfaces in an editor:

sudo gedit /etc/network/interfaces

and add the following:

# The wireless network interface 
iface wlan0 inet dhcp
  wpa-ssid  wireless_network_name
  wpa-psk   wireless_passphrase

(I am assuming you are dealing with a wireless connection, please do clarify if I'm wrong. I'm also assuming you only have one wireless card.)

Now to make sure it is not so easy to see your passphrase:

sudo chmod 600 /etc/network/interfaces

Modify your sudoers file so you can run ifup and ifdown without password

sudo visudo

type i, go to the last line (with the arrow keys) and type

your_username  ALL=(ALL) NOPASSWD: /sbin/ifup wlan0, /sbin/ifdown wlan0

type Esc and then type :wq.

Now test it by running sudo ifup wlan0. Try opening a web page on the browser.

If that worked, now all you need to do is create a shortcut, so open Keyboard and add a custom shortcut. For the command type sudo ifup wlan0.

You might also want to create a shortcut to disconnect. For that the command would be sudo ifdown wlan0.

If you want to reactivate Network Manager, you must first delete/comment the lines you added to /etc/network/interfaces. Then run:

sudo rm /etc/init/network-manager.override
sudo start network-manager


If you are up to it, you can install gksu and for the shortcut command use gksudo ifup wlan0. This way you can skip the editing of the sudoers file (which I wouldn't recommend if you are in unfamiliar territory). With this method you would have to type your password, though.


  1. Arstechnica: Howto deal with Network Manager completely from the command line

  2. Ubuntu Help: NetworkManager

  • It's a mobile broadband connection via USB dongle. Is there a "compromise" between this solution and the presence of the Network connections indicator/menu? I like it and I'd like not to remove Ubuntu standard elements, just adding the shortcut to have both types of access, mouse click and keyboard shortcut (also because, should I reinstall Ubuntu in the future, I'd like to keep the number of personalizations as low as possible). Thank you very much for your help.
    – Andrew
    Jul 13 '13 at 20:18
  • I've edited my answer.
    – edwin
    Jul 13 '13 at 20:33
  • Thank you for your precious help Edwin. I'll choose the first approch and read the nmcli manual and references to see if there's a way to activate a specific connection (sometimes I have two different of them and they are not set to Automatic). I'll also look for 1) how to set in a single statement two commands (how to combine "Enable mobile broadband network" command and "Connection name" execution) and 2) how to make only one shortcut to activate and deactivate the connection, with a conditional construct, always in a single statement. I hope it will be easy. Thank you again.
    – Andrew
    Jul 14 '13 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.