What is a Proxy Server
A proxy server is a server that acts as an intermediary for requests from clients seeking resources on the internet or an external network. Think of it as a go-between who makes requests on behalf of the client, ensuring that anyone outside of your network does not know the details of the requesting host.
Verify if proxy is set on the server
This command will show if there is a proxy server configured on the system:
# echo $http_proxy
Setting Proxy for Command line programs
The http_proxy environment variable is used to specify proxy settings to client programs such as curl and wget. Below are the various examples of using proxy for commandline programs:
1. No username and password required:
To configure proxy without username and password:
# export http_proxy=http://SERVER:PORT/
2. Username and password authentication:
To configure the proxy server with username and password authentication:
# export http_proxy=http://USERNAME:PASSWORD@SERVER:PORT/
3. Domain, username and password required:
To configure proxy with username/password authentication along with the Domain name:
# export http_proxy=http://DOMAIN\\USERNAME:PASSWORD@SERVER:PORT/
Special character handling
Literal backslash characters (\) need to be doubled escape them as shown below.
# export http_proxy=http://DOMAIN\\USERNAME:PASSWORD@SERVER:PORT/
When the username or password uses the @ symbol, add a backslash (\) before the @ – for example:
# export http_proxy=http://DOMAIN\\USERN\@ME:PASSWORD@SERVER:PORT
or
# export http_proxy=http://DOMAIN\\USERNAME:P\@SSWORD@SERVER:PORT
Configuring Proxy in CentOS/RHEL 7 permanently (for processes without shell)
Define the environment variables in /etc/environment file if you want to add a permanent proxy in the CentOS/RHEL 7.
# echo "http_proxy=http://proxy.example.com:3123/" > /etc/environment
Note that unlike a shell script in /etc/profile.d described in the next section, the /etc/environment file is NOT a shell script and applies to all processes without a shell.
Configuring proxy for processes with SHELL
For bash and sh users, add the export line given above into a new file called /etc/profile.d/http_proxy.sh file:
# echo "export http_proxy=http://proxy.example.com:3123/" > /etc/profile.d/http_proxy.sh
For csh and tcsh users, use the following command to set the http_proxy variable in a new file called /etc/profile.d/http_proxy.csh file:
# echo "setenv http_proxy http://proxy.example.com:3123/" > /etc/profile.d/http_proxy.csh
The extension of these files determines which shell will read them. The commands are not interchangeable.
Setting proxy for other programs
To configure yum behind proxy, modify the /etc/yum.conf with the following:
# vi /etc/yum.conf proxy=http://proxy.example.com:3123 proxy_username=yum-user proxy_password=qwerty
Note: Please be aweare that other programs (such as Firefox and Chrome) will have their own internal settings for proxy usage.