How To Configure the Proxy Server On Linux Using Terminal

A proxy server is a dedicated computer or a software system running on a system that acts as an intermediary between an endpoint device, such as a computer, and another server from which a user or client is requesting a service. The proxy server may exist in the same machine as a firewall server or it may be on a separate server, which forwards requests through the firewall. An advantage of a proxy server is that its cache can serve all users. If one or more Internet sites are frequently requested, these are likely to be in the proxy’s cache, which will improve user response time. A proxy can also log its interactions, which can be helpful for troubleshooting.

Configure the Proxy Server On Linux Using Terminal

Configure the Proxy Server On Linux Using Terminal

How Proxy Servers Works?

When a server receives a request for an Internet resource (such as a Web page), it looks in its local cache of previous pages. If it finds the page, it returns it to the user without needing to forward the request to the Internet. If the page is not in the cache, the proxy server, acting as a client on behalf of the user, uses one of its own IP addresses to request the page from the server out on the Internet. When the page is returned, the server relates it to the original request and forwards it on to the user.

In the Linux operating system,  we have the variables like http_proxy, ftp_proxy and https_proxy  through which we can access the Internet via a proxy server on the Linux console.

All of the above-mentioned variables are can be used with tools like elinks, wget, lynx, rsync etc.

I am assuming Linux servers that are behind the proxy servers and can get the Internet connection only via proxy settings.

Configure Proxy Server On Linux Using Terminal

Let’s do it!

Example: 1 Access HTTP base sites via proxy, use below variable
Syntax : # export http_proxy=http://<proxy-server-ip-or-dns-name>:<Port-Number>
# export http_proxy=
Example: 2 Password Protect Proxy Settings
Syntax # export http_proxy=http://USERNAME:PASSWORD@:PORT
# export http_proxy=http://mangesh:********

Using the above command we can configure the proxy server setting along with username and password.

Example: 3 To access secure sites (https) via a proxy  server, enter below variable
Syntax #  export https_proxy=http://<proxy-server-ip-or-dns-name>:<Port-Number>
# export https_proxy=
Example:4 To access ftp based sites via the Proxy server, set the below variable
Syntax # export ftp_proxy=http://<proxy-server-ip-or-dns-name>:<Port-Number>
# export ftp_proxy=

Note: As these variables are declared for the particular session, to set it permanently, define these variables in the file bash.bashrc

# vi /etc/bash.bashrc 
export http_proxy=
export ftp_proxy=
Example: 5  Proxy Settings in APT For Ubuntu
# vi /etc/apt/apt.conf
Acquire::http::Proxy "http://<proxy-server-ip-or-dns-name>:<Port-Number>";
Example:6  Proxy Settings for RSYNC
Syntax # export RSYNC_PROXY="http://<proxy-server-ip-or-dns-name>:<Port-Number>”

# export RSYNC_PROXY="”

How To Check Current Proxy settings

$ env | grep -i proxy

How To Check Your Public IP Address Using Terminal

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

How To Unset Proxy Server

Following commands can be used to disable proxy configurations.

$ unset http_proxy
$ unset https_proxy
$ unset ftp_proxy

Also Read-

»How to Generate SSH Keys on Windows 10 with Ubuntu

If you found this tutorial helpful then Like and Share. If you got something else then feel free to comment.

Mangesh Dhulap

This is Mangesh Dhulap the Founder and Editor of IT SMART TRICKS have 6+ years of Industrial Experience. We expect from our visitors to like, share, and comment on our posts.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.