Please read the whole thing before modifying anything. Ask away if you have doubts with some step.
Approach 1: Using
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
Approach 2: Using
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
/etc/network/interfaces in an editor:
sudo gedit /etc/network/interfaces
and add the following:
# The wireless network interface
iface wlan0 inet dhcp
(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
ifdown without password
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
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.
Arstechnica: Howto deal with Network Manager completely from the command line
Ubuntu Help: NetworkManager