Difference between revisions of "Linux proxy"

From Ever changing code
Jump to navigation Jump to search
Line 1: Line 1:
When you behind a firewall of a company proxy you may need to configure your Linux distro to use it in coure to have access to internet
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 it can be used without or with authentication. Many times this could be your Active Directory login/password combination. It does not need to be user name that you logged on.
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.


Make sure you can resolve the proxy server DNS name otherwise you may need to use IP address.
;The common proxy environment variables are:
http_proxy = URL
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
;Temporary set up per command
  sudo env http_proxy=http://proxyserver.local:8080 apt-get update
  <nowiki>sudo env http_proxy=http://proxyserver.local:8080 apt-get update</nowiki>
  sudo env http_proxy=http://username:password@10.0.0.1:8080 apt-get update
  <nowiki>sudo env http_proxy=http://username:password@10.0.0.1:8080 apt-get update</nowiki>


;Temporary set up per session, remember to use -E with sudo to preserve local environment variables
;Temporary set up per session, remember to use -E with sudo to preserve local environment variables
  export http_proxy=http://proxyserver.local:8080/
  <nowiki>export http_proxy=http://proxyserver.local:8080/</nowiki>
  export ftp_proxy=http://username:password@proxyserver.local:8080/
  <nowiki>export ftp_proxy=http://username:password@proxyserver.local:8080/</nowiki>
  sudo -E apt-get update  
  sudo -E apt-get update  


;Permanent per user
;Permanent per user
Append enviroment variables to ~/.profile
Append enviroment variables to ~/.profile
  http_proxy=http://proxyserver.local:8080/
  <nowiki>http_proxy=http://proxyserver.local:8080/</nowiki>
  sudo -E apt-get update      #still requires to pass on local environment variable to be executed as root  
  sudo -E apt-get update      #still requires to pass on local environment variable to be executed as root  


Line 24: Line 30:
  exec 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:
<nowiki>wget http://username:mypassword@proxy.company.com:8001/</nowiki>
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 =
= Resources =
*[http://askubuntu.com/questions/158557/setting-proxy-from-terminal setting-proxy-from-terminal]
*[http://askubuntu.com/questions/158557/setting-proxy-from-terminal setting-proxy-from-terminal]

Revision as of 12:29, 24 February 2016

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 = 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