How to Set Up a Proxy Server on Ubuntu

Black Framed Eyeglasses On Computer Screen Feature Image Linux

If you’ve ever needed to tweak your network settings for privacy, bypass regional restrictions, or secure data transfers, you’ve likely heard of proxies. With proxies, you can browse the web without any restrictions and also add an extra security layer to your web-related activities.

But how well do proxies work, and how can you set one up on Ubuntu? This guide will cover a detailed overview of getting your proxy up and running on Ubuntu Linux.

What Are Proxies, and How Do They Work?

Proxies are intermediary servers that serve as a gateway between your system and the online world (and here are the best free proxy servers you can use). They work by intercepting your internet activity and passing it through their own servers. You can configure a proxy to handle several traffic types such as FTP, HTTP, and HTTPS.

When you run a proxy, your internet requests are first passed to the proxy server. After that, it passes on to the target website. In the same way, the data from the website returns to the proxy server first, which then relays it back to you. This technique masks your IP address from the websites you visit, providing a layer of anonymity.

Set Up Proxy Server on Ubuntu

Configuring a proxy server on Ubuntu is straightforward. You can set it up either through GUI or from the Linux terminal. Let’s start by configuring a proxy using the GUI method.

Using Desktop GUI

To set up a proxy server on Ubuntu, go to the Activities overview, type Settings, and open it. You can also open Settings from the sidebar of the main Ubuntu window.

Displaying settings icon in the applications menu.

Go to the Network section in the settings menu and select the Proxy option.

Opening proxy setting from the Network section in Ubuntu settings.

Turn on the Network Proxy option and choose either Manual or Automatic configuration.

If you select Manual, you’ll need to specify the port number and IP address of your proxy server. Also, make sure to select the right proxy type such as HTTP, HTTPS, SOCKS5 Host, or FTP.

Specifying IP address and Port number for configuring manual proxy.

You can also add any hosts that should disable the proxy in the Ignored Hosts section at the bottom.

If you select the Automatic option, then you need to input the URL of your proxy’s configuration file.

Specifying autoconfiguration proxy with URL.

That’s it! Save your settings and close the Network Proxy window.

To check if your proxy is set up correctly on Ubuntu, you can open a terminal and run the following command:

echo $http_proxy
Verification of newly set-up proxy using echo command.

If the proxy is set up, you should see the proxy server’s IP and port in the output.

Using Ubuntu Terminal

If you’re comfortable using the terminal, you can set up a proxy on Ubuntu with greater precision and control. You have the option to configure the proxy either temporarily or permanently, and you can apply it for a single user or system-wide.

Here is the command to establish the proxy connection:

export HTTP_PROXY="[username]:[password]@[proxy-web-or-IP-address]:[port-number]"

You will need to replace the username, password, proxy-web-or-IP-address, and port number with your specific details.

The same command can be used for all main types of proxy, simply by replacing HTTP with HTTPS, FTP, and SOCKS Host.

Note: Unfortunately, some programs only detect the uppercase versions, while others only detect the lowercase versions. So, if your terminal shows an error while making a connection, try changing the letter cases of proxy variables.

For example, here is the command to set a temporary proxy without authentication using HTTPS proxy type:

export https_proxy="134.209.29.120:8080"

That’s it! The temporary proxy will be now active for all commands in the current terminal session.

You can also bypass the proxy for local traffic by using the NO_PROXY variable:

export NO_PROXY="localhost,127.0.0.8,::1"

Setting Up Permanent Proxy

One drawback of setting up a temporary proxy using environment variables is that you’ll need to reconfigure it every time you start a new terminal session. To avoid this repetitive task, you can configure a permanent proxy for all your terminal sessions.

You can make proxy settings permanent by modifying the system-wide proxy configuration file “.bashrc” in your Home folder.

To begin, let’s open the “.bashrc” file using nano or any other text editor in the terminal:

sudo nano ~/.bashrc

If you’re using Zsh instead of Bash, you need to edit the Zsh configuration file “.zshrc” instead of “.bashrc”.

At the bottom of this configuration file, define the http_proxy or https_proxy variables:

export http_proxy="134.209.29.120:8080"
export https_proxy="134.209.29.120:8080"
Specifying permanent proxy configuration by editing bashrc file.

Save the changes and close the file.

To apply the updated proxy settings to the existing session, run this:

source ~/.bashrc

The proxy settings will now be active for the current user every time a new terminal session is opened.

Furthermore, if you want these settings to apply to all users, add the proxy variables to the “/etc/environment” file, which is a system-wide configuration file.

Let’s first open the “/etc/environment” file as a root user:

sudo nano /etc/environment

Again, include the specific proxy variables’ details at the end of the file:

export http_proxy="134.209.29.120:8080"
export https_proxy="134.209.29.120:8080"
Configuration permanent proxy for all users by editing /etc/environment file.

Save and close the file. Finally, you can enable the new proxy mode by logging out and then logging back in.

If your proxy server needs your username and password, add this:

export http_proxy="http://username:password@proxy_server:port"

Set Up Proxy Settings for APT

APT, the package manager for Debian-based systems like Ubuntu and Linux Mint, requires some additional configuration to use a proxy.

To begin, open the apt configuration file using any text editor:

sudo nano /etc/apt/apt.conf

Next, add the proxy details in the specified format:

Acquire::http::Proxy "http://proxy-server.com:8080";
Acquire::https::Proxy "http://proxy-server.com:8080";
Specifying proxy for APT in its configuration file.

Your APT will now route through the proxy for all updates and installations.

Apply Proxy Settings for Git & Get

You can also apply the proxy setting for various other console programs such as Git and wget. In software development, Git is a very important tool for managing source code modifications.

You can configure Git with a proxy by modifying its http.proxy setting in your Git configuration file:

git config --global http.proxy http://proxy-server.com:8080
Applying proxy to Git in Ubuntu terminal.

You can do the same for HTTPS proxy type:

git config --global https.proxy https://proxy-server.com:8080

Furthermore, to make sure that the settings are applied, run:

git config --global --get http.proxy
Verification of Git proxy.

wget is a command-line tool that lets you download files from the internet without a browser. To specify a proxy server for wget, simply add the necessary proxy details to the “.wgetrc” file.

Let’s open and edit the wget configuration file:

sudo nano ~/.wgetrc

Add the following proxy details:

use_proxy = yes<br>http_proxy = 134.209.20.120:8080
Applying proxy to Wget command line tool by editing its wgetrc file.

Save the file and exit. The changes take effect immediately.

Things to Try With Ubuntu Proxy Server

Once your proxy is up and running, it opens up a lot of possibilities. For example, you can easily bypass regional blocks and unlock content that’s otherwise not available in your region. Proxies are great for safeguarding your privacy too, as they mask your IP address, keeping your online activities more secure.

You can use a proxy to manage bandwidth and control internet usage. Additionally, when a proxy server is set up to cache content, it stores copies of the websites you frequently visit, which significantly speeds up your browsing.

Difference Between Proxies & VPN

What about VPNs? Aren’t they the same thing? Well, not quite. While both can mask your IP address, a VPN secures all your web traffic, not just specific requests. VPNs provide a higher level of security, making them ideal for sensitive activities like online banking or accessing corporate networks.

On the other hand, proxies are often faster and can be used for specific tasks like bypassing regional restrictions or managing bandwidth without the overhead of encryption.

Wrapping up

Whether you want to bypass content restrictions, improve your online privacy, or enhance your network security, a proxy server can be a valuable tool for you. You can also use Nginx as a reverse proxy, or create a simple web server with darkhttpd.

Image credit: Unsplash. All alterations and screenshots by Haroon Javed.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Haroon Javed
Haroon Javed - Contributor

Haroon is a lifelong tech enthusiast with over five years of experience writing thousands of articles about Linux, programming languages, and more. He loves exploring new technologies and experimenting with them to find innovative ways to use them. Haroon's work has been featured on various online platforms, including HTG, Baeldung, and LinuxHint.