How to configure proxy in Linux Operating System – Using command line method

In this blog we will learn How to configure proxy in Linux Operating System using the command line method. We will go through different way of using proxy as system env variable as well as configuring it for their package managers.

Introduction

An intermediary server that stands in between a client computer and the internet is called a proxy server. It is typically utilized in internal networks to guard against intrusions and allow for unforeseen access. It is also utilized for bandwidth management, content banning and filtering, and internet access control. To access the internet, you must configure a proxy in your web browser or network proxy configuration if your home or workplace network is protected by a proxy server. Typically we see proxy usage in the corporates where they where the IT infra is running behind a protected network and to connect to the outside world we typically have their proxy servers.

Pre-requisite

  • Any versions of Ubuntu or Debian OS installed on the PC/Desktop/Server Hardware.
  • Any version of RHEL, CentOS Stream, Rocky , Alma Linux installed on the PC/Desktop/Server Hardware.
  • User with sudo privileges

You may go through our previous blog post on How To Install Rocky Linux

Proxy for Specific session/User

You might not want to always utilize a proxy in some situations. If so, you can use the terminal to temporarily set up a proxy for the session and once you logout or switch to any other user the setting will lost. The syntax would look like below :

Example , Use the below command for setting HTTP_PROXY

Use the below command for setting HTTPS_PROXY

If the proxy server is not protected by any user credential you can simply use as below

If required to set a permanent proxy for a specific User you can do it by editing the ~/bashrc for that user

Add the below lines to the above file

Or Add the below if without any user credentials

Save and Exit the file. Activate the changes using the below command :

Proxy for All User

If required to set proxy for the whole system to be always connected to the Internet/outside world for all the user on the system you will need to use the file /etc/environment

Add the below lines to the above file

or

Save and exit the file. Activate the changes

Proxy for Apt repo in Debian and Ubuntu

Installing the package from the Ubuntu/Debian repository will need you to set up a proxy for APT. Making a new configuration file at /etc/apt/apt.conf.d/ will allow you to accomplish this:

Add the below content to the file

Or

Save and exit the file. Now you can install the packages using the apt repository. Example,

Proxy for yum and dnf repo in RHEL and its derivatives

Installing the package from the RHEL based operating system repository will need you to set up a proxy for YUM or DNF.

Making a new configuration file at /etc/yum.conf will allow you to accomplish this:

This should work fine . If your proxy server is password protected add the below two lines to the file /etc/yum.conf

Save and exit the file. Test the proxy by installing any packages

Conclusion

In this tutorial we have successfully configured proxy for a linux system for a single session/user as well as for all the system user. Later we also learnt how we can configure the proxy for APT ( Debian & Ubuntu system) and YUM/DNF for RHEL based system to install packages via their package manager. You may also go through the wiki to learn more on Proxy Servers

Leave a comment