Linux proxy

From Ever changing code
Revision as of 21:56, 18 April 2016 by Pio2pio (talk | contribs)
Jump to navigation Jump to search

When you behind a firewall of a company proxy you may need to configure your Linux distro to pass proxy details to the applications in turn to connect to Internet. Most common application like curl, wget, git use an environment variables to know proxy settings but others like Firefox and desktop applications may need to be specifically configured within application itself.

In the examples below depends on your proxy server you need to be authentication. Often it could be your own Active Directory login/password combination but it can be also Internet user login/password credentials.

The common proxy environment variables are
http_proxy = URL
https_proxy =$http_proxy    or   https_proxy = URL
ftp_proxy = URL
no_proxy = string

Make sure you can resolve the proxy server DNS name otherwise you may need to use IP address in the examples below.

Temporary set up per command
sudo env http_proxy=http://proxyserver.local:8080 apt-get update
sudo env http_proxy=http://username:password@10.0.0.1:8080 apt-get update
Temporary set up per session, remember to use -E with sudo to preserve local environment variables
export http_proxy=http://proxyserver.local:8080/
export ftp_proxy=http://username:password@proxyserver.local:8080/
sudo -E apt-get update 
Permanent per user

Append enviroment variables to ~/.profile

http_proxy=http://proxyserver.local:8080/
sudo -E apt-get update       #still requires to pass on local environment variable to be executed as root 
Manage local environment variables
unset HTTP_PROXY   #unset HTTP_PROXY single variable
env -i bash        #unset all local variables back to default on login
exec bash          #unset all local variables back to default on login
Set environment variables with username and password combination

Some proxy servers require authorization to enable you to use them. The authorization consists of username and password, which must be sent by eg. Wget. As with HTTP authorization, several authentication schemes exist. For proxy authorization only the Basic authentication scheme is currently implemented.

You may specify your username and password either through the proxy URL or through the command-line options. Assuming that the company’s proxy is located at ‘proxy.company.com’ at port 8001, a proxy URL location containing authorization data might look like this:

wget http://username:mypassword@proxy.company.com:8001/

Alternatively, you may use the proxy-user and proxy-password options, and the equivalent .wgetrc settings proxy_user and proxy_password to set the proxy username and password.

Resources