How To Use Proxy Server To Access Internet at Shell Prompt With http_proxy Variable

by Vivek Gite on May 9, 2008 · 11 comments

Q. I'm behind a squid proxy server. How do I access internet via proxy server when I use wget, lynx and other utilities from a shell prompt?

A. Linux / UNIX has environment variable called http_proxy. It allows you to connect text based session / application via the proxy server. All you need is proxy server IP and port values. This variable is almost used by all utilities such as elinks, lynx, wget, curl and others.

Set http_proxy shell variable

Type the following command to set proxy server:

$ 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/

How do I 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/
Save and close the file.

How do I use password protected proxy server?

You can simply use wget as follows:
$ wget --proxy-user=USERNAME --proxy-password=PASSWORD http://path.to.domain.com/some.html
Lynx has following syntax:
$ lynx -pauth=USER:PASSWORD http://domain.com/path/html.file
Curl has following syntax:
$ curl --proxy-user user:password http://url.com/

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 11 comments… read them below or add one }

1 Raphael May 9, 2008

For password protected proxies, I know it sometimes work directly included in http_proxy variable (ok it’s not so secure but it can make the work easier) :

$ export http_proxy=http://user:password@server-ip:port/

Reply

2 Ajey February 8, 2011

Great work. This worked for me. Thanks.

Reply

3 Slavko May 9, 2008

It is really correct?

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

Reply

4 vivek May 9, 2008

Slavko,

It was a typo. The faq has been updated.

Reply

5 Pravin September 18, 2008

Hi

I tried this, but still, I cannot ping google or any other site from within the shell.. it says ‘destination host unreachable’..

I’m using Redhat Enterprise 2.4..

Any idea what might be going wrong?

Thanks
Pravin

Reply

6 kiran khairnar December 27, 2010

Until and unless you put the DNS server it won’t ping

Reply

7 Breno April 5, 2009

Very Good Man!
Thanks!

Reply

8 la_89 June 5, 2009

above is good for for text based but for a simple linux user using firefox how can b a proxy server can b used like fedora core 8

Reply

9 ishtiyaq October 4, 2011

proxy setting syntax:
export http_proxy=http://:@:/
export ftp_proxy=http://:@:/

it works for ishtiyaq :)

Reply

10 ishtiyaq October 4, 2011

export http_proxy=http://user:pasword@proxy-server.mycorp.com:port/
export ftp_proxy=http://user:pasword@proxy-server.mycorp.com:port/

Reply

11 El Lobo October 26, 2011

Is there support for excluding sites or a regex from using the proxy?

It seems that there is options for some commands, but is there a centralized option?

I.E. something like:

export no_http_proxy=*.ibm.com,10.0.0.0\24,…

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 2 + 15 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: