Linux Shell Export Proxies (wget/yum/apt..etc)

Most mid to large size companies have multiple Internet connections coming in and out of their locations. All companies I have worked for (mostly telecoms) this was the case. The following is information on how to export an HTTP proxy environment variable that can be used by wget. This is beneficial as not to kill the Internet speed for everyone, just setup a proxy server that routes through a different link or path. The example here is with squid, but this will work with any proxy, just change the TCP port.

Go the the command line and issue the following for a non-authenticated proxy
$ export http_proxy=http://proxy.x.com:3128

Verify that the setting took place
$ printenv | grep http
http_proxy=http://proxy.x.com:3128

Test to see if wget connects through the proxy
$ wget google.com
–09:41:48– http://google.com/
=> `index.html’
Resolving proxy.x.com… 172.x.x.12
Connecting to proxy.x.com|172.x.x.12|:3128… connected.

Proxy request sent, awaiting response… 301 Moved Permanently
Location: http://www.google.com/ [following]
–09:41:48– http://www.google.com/
=> `index.html’
Connecting to proxy.x.com|172.x.x.1|:3128… connected.
Proxy request sent, awaiting response… 200 OK

Length: unspecified [text/html]

[ <=> ] 6,053 –.–K/s
09:41:48 (679.89 KB/s) – `index.html’ saved [6053]

Example using authentication with a proxy
http_proxy=http://user:passwd@proxy.x.com:3128

If you want the change to be permanent (there each time you login), add the line to .bashrc in your “home” directory. Make sure you are logged in with the user that will be accessing the proxy and the following will work

echo “export http_proxy=http://proxy.x.com:3128″ >> ~/.bashrc

Other proxy exports
export https_proxy=”https://proxy.x.com:3128″
export ftp_proxy=”ftp://proxy.x.com:3128″

Note:  This will affect any linux application that checks environment variables for proxy settings.  Also, lynx will only work if you include the http:// prefix on the proxy export, so just doing proxy.x.com:3128 will cause lynx to fail.

~ by Kevin Goodman on November 5, 2008.

One Response to “Linux Shell Export Proxies (wget/yum/apt..etc)”

  1. Oh thank you!

Leave a Reply