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 Servers 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 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=http://proxy.itsmarttricks.com:3128/

Example: 2 Password Protect Proxy Settings

Syntax # export http_proxy=http://USERNAME:PASSWORD@:PORT
# export http_proxy=http://mangesh:********@proxy.itsmarttricks.com.com:3128/

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=http://proxy.itsmarttricks.com:3128

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=http://proxy.etechroom.com:3128/

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=http://proxy.itsmarttricks.com:3128/
export ftp_proxy=http://proxy.itsmarttricks.com:3128/
https_proxy=http://proxy.itsmarttricks.com:3128/

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="http://proxy.itsmarttricks.com:3128”

How To Check Current Proxy settings

$ env | grep -i proxy

How To Check Your Public IP Address Using Terminal

$ wget -q -O - checkip.dyndns.org \
 | 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

That’s all, In this article, we have explained How To Configure the Proxy Server On Linux Using Terminal. I hope you enjoy this article. If you like this article, then just share it and then do subscribe to email alerts for Linux, Windows, macOS, Android, Internet, Firewall and Security, CCTV tutorials. If you have any questions or doubts about this article, please comment.

Share this:

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.