Monday, March 08, 2010

How and where should I change proxy settings in Linux?

PLEASE NOTE THAT IF YOU ARE USING DIRECT CONNECTION TO THE INTERNET THEN THE FOLLOWING POST DOES NOT APPLY. TRYING TO SET THE SETTINGS MAY LEAD TO DISRUPTIONS / DISCONNECTION FROM THE INTERNET.

How and where should I change proxy settings in Linux? This is a most frequent question posed by newbie (and not so new) Linux users ? This mountain can be scaled in three steps.

Step 1 Using proxy to get simply connected to the internet

Just change proxy setting in Firefox and/ or browser of your choice and start using internet. Ignore the rest of urges of Linux to get updates etc and life will be cool and simple.


Of course life cannot continue to be so simple. One has to after all install programs etc.

Step 2 Adding proxy for system-wide settings

Now the next step is to setup proxy for "system-wide" setting. If using GNOME got to the System-> Preferences -> Network Proxy. Typical settings could be ip address/ host name of the proxy server and port name (typically 8080).  Click system-wide settings button and then authenticate by the root password. This would add system-wide system proxy settings and ability to use package managers and instant messengers.

Step 3 Adding proxy to the terminal

Reading through the manuals/ howtos (including those on this blog) the sudo apt-get install (or yum or other variants of package install commands) frequently need proxy settings. The proxy settings can be setup via the following command sequence.

Edit your .bashrc file present in home directory in your favorite editor. Here vi is used for demonstration.
$ vi .bashrc
Go to the end and add the following please note # indicates comments its healthy practice to write comments so that later we know why we wrote the particular lines.
# Proxy settings
export http_proxy="http://MY_PROXY_IP_OR_HOST:MY_PROXY_PORT"
export ftp_proxy="http://MY_PROXY_IP_OR_HOST:MY_PROXY_PORT"

Please ensure to replace MY_PROXY_IP_OR_HOST by the proxy server ip or host name and MY_PROXY_PORT by port number (typically 8080).

Close the terminal and start again. Test out by writing export in the command line and it should be followed by a long list and at the end you should find.

declare -x http_proxy="http://MY_PROXY_IP_OR_HOST:MY_PROXY_PORT"
declare -x ftp_proxy="http://MY_PROXY_IP_OR_HOST:MY_PROXY_PORT"

{Please note the MY_PROXY_IP _OR_HOST and PROXY_PORT will be replaced by the ip/ host name and port number you specify earlier}

A simple test whether the settings have been done is by the following command (if available). It should open the command line browser and open google's webpage.
$ w3m www.google.com

Now the apt-get install and other commands requiring connection to internet via proxy should work.

No comments: