Setting your proxy in CentOS and Red Hat


Most organizations funnel all Internet-bound traffic through a proxy server. In environments such as these you will need to configure your Red Hat-based distribution to pass traffic to the proxy server.

In this article I will provide instructions on how to configure your proxy for various use cases, from a default global configuration to temporary individual configurations.

The following instructions are not inherent to RedHat distributions only. They can be applied to any Linux distribution with little or no conversion.

Environment Variables

Setting the proxy on a Linux installation is primarily done via setting environment variables. There are three variables available – for HTTP traffic, HTTPS traffic, and by-pass traffic.

Sets an endpoint for all HTTP traffic traversing port 80.

Similar to HTTP_PROXY, this sets an endpoint for all traffic SSL\TLS encrypted traffic traversing port 443.

A comma-delimited list of subnets, IP addresses, hostnames and domain names to exclude from proxy. Traffic matching any of the patterns set here will go directly to the destination host.

The export command is used to set environment variables. The follow three examples show you how to set your HTTP, HTTPS and NO_PROXY settings.

export http_proxy=http://my.proxy:8080
export https_proxy=https://my.proxy:8443

Proxy settings set this way will not persist beyond your user session, and they will only apply to your current user session. In the next section creating persistent proxy settings will be covered.

Persistent User Proxy Settings

When we export variables as environment variables the lifespan is only as long as the user session. In order to have to have a persistent configuration we can use a users’ profile script.

  1. Open the profile script for a user into a text editor
  2. Add lines to the configuration to export your desired proxy environment variables.
    export http_proxy=http://my.proxy:8080
    export https_proxy=https://my.proxy:8443
  3. To apply the proxy settings to your active session, use the source command against the profile script.
    source ~/.profile

Global Proxy Settings

When you want your proxy settings to persist globally, for every user account on your server, you can add the proxy environment variables to the default profile script. The default profile is applied every time a user creates a new session, and it runs prior to the user’s profile.

  1. Open the default profile script into a text editor
    sudo vi /etc/default
  2. Add the desired proxy environment variables to the bottom of the file.
    export http_proxy=http://my.proxy:8080
    export https_proxy=https://my.proxy:8443
  3. To apply the settings to your current user session the source command against the defauilt profile.
    source /etc/default