How to use proxy server on CentOS (Entire system and per user)

How to use proxy server on CentOS (Entire system and per user)

If our server is behind firewall or cannot access Internet, we need to use proxy server to access Internet or outside network.

This article explains how to set up proxy server on CentOS. We are going to set up HTTP/HTTPS/FTP proxy server.

Also, this explains how to set up proxy server for yum command. In addition, we talk about how to avoid using proxy server.



 Set up proxy server on entire system

If we need to set up proxy server on entire CentOS system (for all users and programs), we need to add proxy server settings into /etc/environment file.

http_proxy is for HTTP protocol, https_proxy is for HTTPS protocol. Also, ftp_proxy is for FTP protocol setting.

The reason why we need to set up all lower case settings (http_proxy, https_proxy, sftp_proxy) and all upper case (HTTP_PROXY, HTTPS_PROXY, SFTP_PROXY) is that some programs accept only lower case version or upper case version.

Also, if we put domain names or server names into no_proxy setting (each item needs to be separated by comma), we can avoid using proxy server only for the listed domains or servers.
$ sudo vi /etc/environment

http_proxy="http://proxy-server.example.com:8080/"
HTTP_PROXY="http://proxy-server.example.com:8080/"
https_proxy="https://proxy-server.example.com:8080/"
HTTPS_PROXY="https://proxy-server.example.com:8080/"
ftp_proxy="ftp://proxy-server.example.com:8080/"
FTP_PROXY="ftp://proxy-server.example.com:8080/"
no_proxy=".example.co.jp,.test.local,server1.example.com,server2.example.com"

Set up proxy server for each Linux user

If we need to set up proxy server for particular user (not entire system), we need to set up the following settings into the user's setting file. If we are using bash, we need to put the settings into ~/.bash_profile file. If we are using zsh, we need to put the settings into ~/.zsh_profile file.
$ vi ~/.bash_profile

http_proxy="http://proxy-server.example.com:8080/"
HTTP_PROXY="http://proxy-server.example.com:8080/"
https_proxy="https://proxy-server.example.com:8080/"
HTTPS_PROXY="https://proxy-server.example.com:8080/"
ftp_proxy="ftp://proxy-server.example.com:8080/"
FTP_PROXY="ftp://proxy-server.example.com:8080/"
no_proxy=".example.co.jp,.test.local,server1.example.com,server2.example.com"

How to set up proxy server for yum command

In order to set up proxy server for yum command, we need to put the following setting into /etc/yum.conf file. Once we set up the following setting, we can install or update yum (rpm) package through proxy server.

$ sudo vi /etc/yum.conf
 
proxy=http://proxy-server.example.com:8080/