Setting proxies with http_proxy variable

Using proxies to access sites blocked by your organization is a common thing. Problem arises for people who loves to work in command-based environment and browse internet in terminal itself. This post solves their problem.

Linux and other Unix-based systems have environment variable http_proxy which is used by internet command line utilities like curl,wget,lynx etc. All you need is proxy server IP address (URL) and port values.

Setting up the http_proxy variable:

Fire up you shell and type in following

$ export http_proxy=http://server-ip:port/

$ export http_proxy=http://127.0.0.1:3128/

$ export http_proxy=http://proxy-server.mycorp.com:3128/

If the proxy server requires a username and password then add these to the URL. For example, to include the username foo and the password bar:

$ export http_proxy=http://foo:bar@server-ip:port/

$ export http_proxy=http://foo:bar@127.0.0.1:3128/

$ export http_proxy=http://USERNAME:PASSWORD@proxy-server.mycorp.com:3128/

How to setup proxy variable for all users?

To setup the proxy environment variable as a global variable, open /etc/profile file:

$ vi /etc/profile

Add the following information:

export http_proxy=http://proxy-server.mycorp.com:3128/

OR

export http_proxy=http://USERNAME:PASSOWRD@proxy-server.mycorp.com:3128/

Save and close the file.

How do I use password protected proxy server using various command line options?

You can simply use wget command as follows:

$ wget –proxy-user=USERNAME –proxy-password=PASSWORD http://path.to.domain.com/some.html

Lynx command has the following syntax:

$ lynx -pauth=USER:PASSWORD http://domain.com/path/html.file

Curl command has following syntax:

$ curl –proxy-user user:password http://url.com/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s