Pages

Thursday, October 27, 2011

Setting up network proxy in Ubuntu

Method 1: (Graphical)
Note: You probably need this method in order for the synaptics packet manager or the updates to work.
If you are using the Internet behind a proxy, then in order for apt and other Internet related services to work you need to configure an Internet proxy. You can do this using System/Preferences/Network Proxy. After setting the IP and port click on Apply system wide. It will ask for your password twice. You are done.
A note on the above method: This method works but when un-setting the proxy you may run into bugs, so this method is not recommended.

Manual Method (recommended)
You can set the proxy manually in the terminal (note: This method only works for applications that run in the terminal).

export http_proxy=http://192.168.1.1:8080
ftp_proxy=ftp://192.168.1.1:8080

Replace the IP and port in example with your proxy's IP and port.
Then you can test the connection using

wget www.yahoo.com
rm index.html

If wget is able to download the page it means your proxy has been configured correctly, the rm in the above command has been used to delete the test page downloaded using wget.
To unset the proxy

unset http_proxy
unset ftp_proxy

A known bug:
apt-get does not work when used with sudo, if you see that the downloading is getting stuck and not proceeding at all. You should probably use the following method


sudo su
export http_proxy=http://192.168.1.1:8080
apt-get install 

Additional notes:
If you have opened up multiple tabs of terminal,you would have to set proxy in each tab independently. This proxy setting does not hold once you close terminal.

Permanent method:
If you wish to setup proxy permanently, i.e. whenever you open up terminal the proxy is already set; then you need to make changes to your ~/.bashrc file as super user.

sudo gedit ~/.bashrc

When a window pops up enter the following lines at the very end of the file

export http_proxy=http://192.168.1.1:8080
export ftp_proxy=ftp://192.168.1.1:8080

Now you can either restart the terminal or

source ~/.bashrc

In order to remove the proxy in the future just simply comment/remove the lines you added

Special case: If you want to set proxy for all users, not just your own user, then you need to make changes mentioned above in the /etc/bash.bashrc

No comments:

Post a Comment