How to apply a system wide proxy?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 9
  • Red Hat Enterprise Linux 10

Issue

Procedure to update proxy for all user shells and yum

How to confirm the proxy is set on the server?

Resolution

This command will show if there is a proxy server configured on the system:

$ echo $http_proxy
$ echo $https_proxy

Command line programs

The http_proxy environment variable is used to specify proxy settings to client programs such as curl and wget for HTTP protocol.
Similarly https_proxy environment variable is used to specify proxy settings to client programs such as curl and wget for HTTPS protocol.

Note that usually https_proxy refers to same proxy as specified for http_proxy.

No username and password required:

$ export http_proxy=http://SERVER:PORT/
$ export https_proxy=http://SERVER:PORT/

Username and password authentication:

$ export http_proxy=http://USERNAME:PASSWORD@SERVER:PORT/
$ export https_proxy=http://USERNAME:PASSWORD@SERVER:PORT/

Domain, username and password required:

$ export http_proxy=http://DOMAIN\\USERNAME:PASSWORD@SERVER:PORT/
$ export https_proxy=http://DOMAIN\\USERNAME:PASSWORD@SERVER:PORT/

Special character handling:

Literal backslash characters (\) need to be doubled:

$ export http_proxy=http://DOMAIN\\USERNAME:PASSWORD@SERVER:PORT/
$ export https_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

To remove the above exported setting use below command.

$ unset http_proxy
$ unset https_proxy

Making this permanent

  • Define the environment variables in /etc/environment file:

    # echo "http_proxy=http://proxy.example.com:3128/" > /etc/environment
    # echo "https_proxy=http://proxy.example.com:3128/" >> /etc/environment
    
  • To apply the changes or to reload the setting made in /etc/environment file:

    # source /etc/environment
    
  • To remove the changes made through /etc/environment, First comment the line which you want to remove and then run unset <variable> command.

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 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:3128/" > /etc/profile.d/http_proxy.sh
    # echo "export https_proxy=http://proxy.example.com:3128/" >> /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:3128/" > /etc/profile.d/http_proxy.csh
    # echo "setenv https_proxy http://proxy.example.com:3128/" >> /etc/profile.d/http_proxy.csh
    

The extension of these files determines which shell will read them. The commands are not interchangeable.

Other programs

To configure yum behind proxy, modify the yum.conf with the following:

proxy=http://proxy.example.com:3128 
proxy_username=yum-user 
proxy_password=qwerty

Other programs (such as Firefox) will have their own internal settings for proxy usage.

Components
Category
Tags

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.