HowTo : Use a Proxy on the Linux 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 variables are used by almost all Linux command line utilities such as ftp, wget, curl, wget, ssh, apt-get, yum and others.

Setting Proxy Variable

Use the following syntax to configure the proxy for http, https and ftp traffic on the Linux command line :
$ export http_proxy="http://proxy-server:port"
$ export https_proxy="https://proxy-server:port"
$ export ftp_proxy="http://proxy-server:port"

Use the following syntax if the proxy server requires authentication :
$ 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"

If your password contains special characters, you must replace them with ASCII codes.

For example At symbol "@" should be replaced by "%40" (e.g. p@ssword = p%40ssword).

Testing Proxy

Use the following command to check current proxy settings :
$ env | grep -i proxy

You can test the proxy by checking your public IP address from the command line :
$ wget -q -O - \
| sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

You may also use the time command to test the differences in the connection speed with proxy and without it :
$ time wget -q -O - \
| sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

Or you can easily test the Internet download speed with the following command :
$ wget --output-document=\

Unsetting Proxy Variable

Use the following commands to disable proxy :
$ unset http_proxy
$ unset https_proxy
$ unset ftp_proxy

Easy Proxy Usage

If you use the same proxy server for http, https and ftp traffic you can use the following commands to set and unset proxy :
$ export {http,https,ftp}_proxy="http://proxy-server:port"
$ unset {http,https,ftp}_proxy

If you have to use the proxy very often, you can create a bash shell function as follows (add to your ~/.bashrc) :

# 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.

$ . ~/.bashrc

Now use setproxy and unsetproxy commands to make proxy usage easier;)

Lists of Free Public Proxy Servers

BE ALERT! Free Public Proxy Servers can insert your IP address into the headers of requests or listen to your traffic! Don't use them to transfer sensitive data and do not expect for anonymity!

and so on ...

Even if you are using proxy, all your DNS queries still go to the DNS server of your ISP. So if you are looking for anonymity, don't forget to put some Public DNS Servers into your '/etc/resolv.conf' file, or use DNSCrypt.