How to Configure Proxy Settings on Ubuntu 20.04

December 10, 2020

Introduction

Using a proxy server as an internet access intermediary is a common business scenario. However, personal users can also benefit from increased network security, privacy, and speed provided by proxies.

In this tutorial, you will learn how to set up your Ubuntu 20.04 system to work with a proxy server.

How to Configure Proxy Settings on Ubuntu 20.04

Prerequisites

  • Ubuntu 18.04 or later
  • Access to terminal with sudo privileges
  • Proxy info (web or IP address, username, and password)

Note: If you wish to set up one of your machines to act as a proxy, refer to How to Set Up & Install Squid Proxy Server on Ubuntu.

Setting Up Proxy with Ubuntu Desktop GUI

1. To access proxy settings using the Ubuntu GUI, open Ubuntu’s main Settings.

2. Select the Network setting in the menu on the left side of the window.

3. Then, click the cog in the Network Proxy section.

Accessing proxy settings in Ubuntu GUI

4. A Network Proxy dialogue appears. Choose Manual and enter your proxy info into the fields below.

Filling out proxy info in Ubuntu GUI proxy settings

5. Exit the dialogue and Ubuntu will automatically apply the proxy settings.

Setting up Proxy With Ubuntu Desktop Terminal

Use the command line interface for more granular control of proxy settings. This allows you to:

  • Make temporary or permanent changes to the configuration.
  • Set up proxy for a single user or for all users.

Setting Up Temporary Proxy for a Single User

A temporary proxy connection resets after a system reboot. To establish such a connection for the current user, use the export command.

The syntax for establishing a temporary proxy connection is:

export HTTP_PROXY=[username]:[password]@[proxy-web-or-IP-address]:[port-number]
export HTTPS_PROXY=[username]:[password]@[proxy-web-or-IP-address]:[port-number]
export FTP_PROXY=[username]:[password]@ [proxy-web-or-IP-address]:[port-number]
...
export NO_PROXY=localhost,127.0.0.1,::1

Provide the proxy address (web or IP), followed by the port number. If the proxy server requires authentication, add your proxy username and password as the initial values.

This is what the set of commands should look like in terminal:

Using export command to set up temporary proxy

The purpose of the NO_PROXY line is to tell the system that local traffic should ignore the proxy.

Setting Up Permanent Proxy for a Single User

As stated above, proxy settings configured through a terminal window reset after you reboot your system. To make permanent changes for a single user, edit the .bashrc file.

1. Open the file with a text editor of your choice:

sudo nano ~/.bashrc

2. Now add the following lines at the bottom of the .bashrc file:

export HTTP_PROXY="[username]:[password]@[proxy-web-or-IP-address]:[port-number]"
export HTTPS_PROXY="[username]:[password]@[proxy-web-or-IP-address]:[port-number]"
export FTP_PROXY="[username]:[password]@ [proxy-web-or-IP-address]:[port-number]"
...
export NO_PROXY="localhost,127.0.0.1,::1"
Editing .bashrc file in Nano

3. Save and exit the file.

4. Then, run the following command in to apply the new settings to the current session:

source ~/.bashrc

Setting Up Permanent Proxy for All Users

To permanently set up proxy access for all users, you have to edit the /etc/environment file.

1. First, open the file in a text editor:

sudo nano /etc/environment

2. Next, update the file with the same information you added to the .bashrc file in the previous scenario:

export HTTP_PROXY="[username]:[password]@[proxy-web-or-IP-address]:[port-number]"
export HTTPS_PROXY="[username]:[password]@[proxy-web-or-IP-address]:[port-number]"
export FTP_PROXY="[username]:[password]@ [proxy-web-or-IP-address]:[port-number]"
...
export NO_PROXY="localhost,127.0.0.1,::1"
Editing the /etc/environment file in Nano

3. Save the file and exit. The changes will be applied the next time you log in.

Setting Up Proxy for APT

On some systems, the apt command-line utility needs a separate proxy configuration, because it does not use system environment variables.

1. To define proxy settings for apt, create or edit (if it already exists) a file named apt.conf in /etc/apt directory:

sudo nano /etc/apt/apt.conf

2. Add the following lines to the file:

Acquire::http::Proxy "http://[username]:[password]@ [proxy-web-or-IP-address]:[port-number]";
Acquire::https::Proxy "http://[username]:[password]@ [proxy-web-or-IP-address]:[port-number]";
Editing /etc/apt/apt.conf in Nano

3. Save the file and exit. The configuration will be applied after a reboot.

Conclusion

This tutorial provided instructions on how to set up proxy settings on Ubuntu 20.04. You should now know how to make temporary and permanent changes to your system’s proxy configuration, for a single user or for the entire system.

Was this article helpful?
YesNo
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
Next you should read
How to Install and Configure Nginx on Ubuntu 20.04
October 1, 2020

Nginx is an open-source application used for managing web servers, load balancing, and security. This...
Read more
How to Install Squid Proxy Server on CentOS 7
July 26, 2019

Squid Proxy specifically allows a server to cache frequently visited web pages. When a user seeks a web page...
Read more
How to Set Up & Install Squid Proxy Server on Ubuntu 18.04
February 15, 2019

Squid is a Linux-based proxy application that can be used for filtering traffic, security, DNS lookups, and...
Read more
How to Set up & Use NGINX as a Reverse Proxy
January 8, 2019

Nginx (pronounced 'Engine X') is a reverse proxy application. A standard proxy server works on behalf of...
Read more