A proxy server is an intermediate server that sits between the client computer and the internet. Generally, it is used in internal networks for unexpected access and to prevent attacks. It is also used to control internet access, bandwidth control, and content filtering and blocking.

If your office or home network is behind a proxy server then you will need to set up a proxy in your web browser or network proxy setting to access the internet.

In this tutorial, we will show you how to set up proxy settings and apt-proxy in Ubuntu 22.04 Server and Desktop system. The same steps are working on Ubuntu 20.04 as well.

Prerequisites

  • Ubuntu 22.04 desktop or Ubuntu 20.04 Desktop installed on your pc.
  • Root access via sudo.

Setup Proxy on Ubuntu Desktop

In order to set up a proxy on an Ubuntu desktop, open the System Settings as shown below:

<img alt="Ubuntu System Settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/10/echo/ubuntu-settings.png635a388e63098.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="432" loading="lazy" src="data:image/svg xml,” width=”750″>

<img alt="Ubuntu Network Settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/10/echo/ubuntu-network-settings.png635a388fe3a21.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="432" loading="lazy" src="data:image/svg xml,” width=”750″>

Click on the Network => Network proxy. You should see the following screen:

<img alt="Ubuntu network proxy" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/10/echo/ubuntu-proxy-settings.png635a389227b3e.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="432" loading="lazy" src="data:image/svg xml,” width=”750″>

In the “Method” drop-down list, select Manual, provide your proxy server IP, and port number and click on the “Apply system-wide” button to apply the changes.

Setup Proxy for Single User

In some cases, you don’t want to use a proxy every time. In that case, you can set up a temporary proxy from the terminal windows.

To export the HTTP_PROXY variable temporarily, run the following command in your terminal:

export HTTP_PROXY=username:[email protected]:8181

To export the HTTPS_PROXY variable temporarily, run the following command in your terminal:

export HTTPS_PROXY=username:[email protected]:8182

If you want to set up a permanent proxy for a single user. You can do it by editing the file ~/.bashrc for a specific user:

nano ~/.bashrc

Add the following lines at the end of the file:

export http_proxy=username:[email protected]:8181
export https_proxy=username:p[email protected]:8182

Save and close the file then activate the new proxy setting with the following command:

source ~/.bashrc

Setup Permanent Proxy for All User

If you want to set up a proxy setting for all users then you can set up it by editing the /etc/environment file:

nano /etc/environment

Add the following lines at the end of the file:

export http_proxy=username:[email protected]:8181
export https_proxy=username:[email protected]:8182

Save and close the file then activate the new proxy setting with the following command:

source /etc/environment

Setup Proxy for APT

You will need to set up a proxy for APT if you want to install the package from the Ubuntu repository. You can do it by creating a new configuration file at /etc/apt/apt.conf.d/:

nano /etc/apt/apt.conf.d/proxy.conf

Add the following lines:

Acquire::http::Proxy "http://username:[email protected]:8181/";
Acquire::https::Proxy "https://username:[email protected]:8182/";

Save and close the file when you are finished. You can now install any packages from the Ubuntu repository in your system

Conclusion

In the above guide, I have shown you how to set up a proxy on Ubuntu using different methods. I hope you have now enough knowledge of the proxy settings.