Linux Proxy Server Settings – Set Proxy For Command Line

To use a proxy on the Linux command-line, you can set the environment variables http_proxy, https_proxy or ftp_proxy, depending on the traffic type.

These proxy server settings are used by the almost all Linux command-line utilities, e.g. ftp, wget, curl, ssh, apt-get, yum and others.

If you don’t know yet which proxy server to use, you can take one from the lists of the free public proxy servers at the end of this article.

Cool Tip: Need to improve security of the Linux system? Encrypt DNS traffic and get the protection from DNS spoofing! Read more →

Export Proxy Server Settings

Set these variables to configure Linux proxy server settings for the command-line tools:

$ export http_proxy="http://PROXY_SERVER:PORT"
$ export https_proxy="https://PROXY_SERVER:PORT"
$ export ftp_proxy="http://PROXY_SERVER:PORT"

If a proxy server requires authentication, set the proxy variables as follows:

$ export http_proxy="http://USER:PASSWORD@PROXY_SERVER:PORT"
$ export https_proxy="https://USER:PASSWORD@PROXY_SERVER:PORT"
$ export ftp_proxy="http://USER:PASSWORD@PROXY_SERVER:PORT"

Special Characters: If your password contains special characters, you must replace them with ASCII codes, for example the at sign @ must be replaced by the %40 code, e.g. p@ssword = p%40ssword.

Test The Proxy Server From The Linux Command-Line

As only you have configured a proxy it is time to ensure that it works as expected.

First off all it is required to check that the proxy server settings are set in the corresponding proxy variables.

Than it is required to ensure that your public IP address has changed.

Also it would be interesting to measure and compare response time of the remote resources and the Internet speed with and without proxy.

Check the current proxy server settings:

$ env | grep -i proxy

Check your public IP address from the Linux command-line:

$ wget -q -O - checkip.dyndns.org \
| sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

Compare the difference in the response time with the configured proxy and without it:

$ time wget -q -O - checkip.dyndns.org \ 
| sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

Check the Internet download speed through the proxy:

$ wget --output-document=\
/dev/null http://speedtest.wdc01.softlayer.com/downloads/test500.zip

Unset Linux Proxy Variables

Use the following commands to disable proxy:

$ unset http_proxy
$ unset https_proxy
$ unset ftp_proxy

Cool Tip: Stay anonymous during port scanning! Use Nmap + Tor + ProxyChains! Safe and easy penetration testing! Read more →

Automate Proxy Server Settings In Linux

If you use the same proxy server settings for the https, http and ftp traffic, you can use the following commands to set and unset the proxy settings:

$ export {http,https,ftp}_proxy="http://PROXY_SERVER:PORT"
$ unset {http,https,ftp}_proxy

If you use a proxy server often, you can create Bash functions as follows (add to your ~/.bashrc file):

# Set Proxy
function setproxy() {
    export {http,https,ftp}_proxy="http://PROXY_SERVER:PORT"
}

# Unset Proxy
function unsetproxy() {
    unset {http,https,ftp}_proxy
}

Reload your ~/.bashrc file.

$ source ~/.bashrc

Now use the setproxy and unsetproxy commands to set and unset Linux proxy server settings.

Lists of Free Public Proxy Servers

WARNING: Free public proxy servers can insert your IP address into the headers of requests or sniff your traffic! Don’t use them to transfer sensitive data and do not expect anonymity!

Cool Tip: Even if you use proxy server, all your DNS queries still go to the name servers of your ISP (Internet Service Provider)! Improve anonymity, by using free public name servers! Read more →

Was it useful? Share this post with the world!

7 Replies to “Linux Proxy Server Settings – Set Proxy For Command Line”

  1. You can use no_proxy or NO_PROXY that includes a comma delimited list of domains, subdomains, hostnames, and/or IP addresses that are exempt from the {http{,s},ftp,rsync}_proxy variables.

    So something like
    export no_proxy=’localhost,127.0.0.1,.example.com,.shellhacks.com’
    would exempt localhost, 127.0.0.1, *.example.com, and *.shellhacks.com from the other proxy variables.

  2. After adding these lines I got same error “connection refused”.

  3. TY worked

  4. Hi, after following the steps, my public IP has indeed changed based on the results from the terminal. However when I checked my IP using the web browser, it is still my original public IP and not the proxy IP. Can you please tell me why it is so?

  5. I have a proxy server on a debian 10 and I want to connect a centOS machine, which goes out through my proxy, how can I do it through the command line, because through the graphical interface I use the adapter and it works for me, but when I make configurations in the yum. or in echo $ http_proxy, it doesn’t work for me

  6. It’s very helpful infomation to me
    Thank you~

Leave a Reply