50% OFF Residential Proxies for 9 months — use code IPR50 at checkout

Get The Deal

How to Set Up a Proxy on Ubuntu: A Complete Technical Guide

Learn about Ubuntu proxies and how to set up a temporary or a system-wide permanent proxy server and configure proxy settings on Ubuntu Linux.

How to Set Up a Proxy on Ubuntu: A Complete Technical Guide

Key Takeaways

  • Proxies on Ubuntu systems increase privacy, access, and performance, enabling various tasks from web scraping to simple browsing.

  • Ubuntu supports all proxy protocols and types, although in many networking, automation, and development cases, SOCKS5 datacenter proxies are recommended.

  • You can configure proxy settings from the Ubuntu main settings menu and in the terminal using export or other commands.

It's a common misconception that Ubuntu Linux is just for programmers or tech experts. Even advanced Ubuntu proxy integration isn't more complicated than in Windows or macOS systems. In some regards, it might even be more convenient to use Ubuntu for various networking, development, or automation tasks.

Why Set Up a Proxy on Ubuntu?

As with any other operating system, proxy servers bring privacy, access, and performance benefits to Ubuntu. Once set up system-wide or for a particular application, it will route the traffic and change your IP address, which brings many benefits.

  • Privacy and anonymity. It's much more difficult for third parties to track your online activity if you use IP addresses from proxies.
  • Access control. A proxy server will allow you to bypass regional and other restrictions that might be imposed on your original IP address.
  • Performance. Proxies speed up the loading of services and improve performance in other ways in various scenarios.

Proxy servers are especially beneficial in tasks like web scraping, automation, and testing. Such uses are common with Ubuntu (and Linux in general) users. Proxies allow you to run necessary scripts and bots that would be limited otherwise.

Types of Proxies Compatible with Ubuntu

While there are some differences in configuration and compatibility, all major proxy protocols are compatible with Ubuntu systems.

  • HTTP/HTTPS proxy servers work with most web-based apps. The HTTPS proxy version should be preferred as it's more secure. HTTP is recommended only if HTTPS is not supported.
  • SOCK5 proxies support TCP and UDP, work with most applications and command line tools. Recommended for most scraping, development, networking, or other tasks.

Both residential and datacenter proxies are suitable for use with Ubuntu systems, although the choice rests on your use case. Residential proxies stand out for the legitimacy of their IP addresses. They should be preferred for tasks like multi-accounting, bypassing geo restrictions, and difficult web scraping targets.

For most networking, automation, development, or similar use cases, datacenter proxies are a better choice. They are generally faster while supplying you with more IP addresses for the same price. In some cases, mobile proxies are needed to access mobile-only content.

Ubuntu Proxy Setup via System Settings (GUI)

We'll use IPRoyal's residential proxies as a setup example. All the required details for configuring proxy settings in Ubuntu can be found in the dashboard, as shown below. Replace the placeholders with them in the following steps.

IMG1.png

In case you need more detailed information on purchasing and setting up residential proxies, check out our quick start guide. Once you have the proxy credentials, you can set up proxies in Ubuntu's settings following the steps below.

  1. Click on the system menu in the top-right corner and press on the Settings icon.
  2. Find Network and click on proxy.
  3. Toggle the Network proxy option to ON in the network proxy window.
  4. Set network proxy configuration to Manual.
  5. Find your proxy type from the list and enter the proxy details there.
  6. Save.
IMG2.png

Proxies might require username and password authentication. You'll be prompted to enter them when an application, such as the Mozilla Firefox browser, sends the first request. Alternatively, you can set up IP whitelisting authentication.

These steps will ensure that all applications, such as your browser or the software center, will use a proxy server connection. The settings will persist until you change them again, but they will not apply to terminal applications like cURL or APT.

Set Up Proxy Using Environment Variables

Temporary proxy in the terminal

Another way to set up proxy servers in Ubuntu is by using the terminal. The commands for both temporary proxy configurations are quite similar to the steps for macOS.

  1. Press the Activities Overview button in the lower left corner. Select a terminal from the list (or type in Terminal).
  2. If you're using HTTP/HTTPS proxies, use the following commands.
export http_proxy="http://PROXY_HOST:PROXY_PORT"
export https_proxy="http://PROXY_HOST:PROXY_PORT"

If you use SOCKS5 proxies, enter these commands:

export http_proxy="socks5://PROXY_HOST:PROXY_PORT"
export https_proxy="socks5://PROXY_HOST:PROXY_PORT"

3. Your proxies might require username and password authentication. If that is the case, include it in the export command as such.

export http_proxy="http://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT"
export https_proxy="http://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT"

Authentication for SOCKS5 proxies works in a similar way:

export http_proxy="socks5://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT"
export https_proxy="socks5://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT"

4. Finally, you can verify whether the proxy variables are set correctly using the following command:

env | grep -i proxy

These steps set a proxy for Ubuntu only in the current terminal session. Once it's closed, the proxy settings will need to be reinstated. Follow the steps below if you need to set proxies in Ubuntu permanently.

Permanent proxy in terminal

To set up a permanent proxy for your Ubuntu system, you will need to edit the .bashrc file by setting environmental variables there.

  1. Press the Activities Overview button in the lower left corner. Select a terminal from the list (or type in Terminal).
  2. Start with the following command, which opens the .bashrc file:
sudo nano ~/.bashrc

3. Then, edit the file by running the relevant export commands as in the steps for the temporary proxy. Here are the commands for an HTTP/HTTPS proxy:

export http_proxy="http://PROXY_HOST:PROXY_PORT"
export https_proxy="http://PROXY_HOST:PROXY_PORT"

The SOCKS5 commands are also the same:

export http_proxy="socks5://PROXY_HOST:PROXY_PORT"
export https_proxy="socks5://PROXY_HOST:PROXY_PORT"

4. In case your proxies require authentication, username and password can be added to the commands as well. Examples for HTTP/HTTPS and SOCKS5 proxies:

export http_proxy="http://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT"
export https_proxy="http://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT"
export http_proxy="socks5://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT"
export https_proxy="socks5://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT"

5. Lastly, you need to save the .bashrc file and exit the settings.

source ~/.bashrc

These steps will configure proxies permanently for the user who runs them. It includes both the apps and settings of Ubuntu as well as various command-line tools.

Configure APT to Use a Proxy

The Advanced Package Tool (APT) is a convenient package manager for Debian-based Linux systems like Ubuntu. Mainly used for software management, it might require specific proxy servers for installing various updates or connecting to apps. To do it, you'll need to edit the proxy configuration file of APT:

  1. Press the Activities Overview button in the lower left corner. Select a terminal from the list (or type in Terminal).
  2. Open the apt.conf file.
sudo nano /etc/apt/apt.conf

3. Add the relevant lines:

Acquire::http::Proxy "http://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT";
Acquire::https::Proxy "https://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT";

Unfortunately, APT does not support SOCKS5 proxies natively, so you'll need to use third-party tools like ProxyChains.

4. Save (Ctrl+O) and exit the terminal.

Set Proxy for Command-Line Tools

If setting permanent and temporary proxies in Ubuntu is too much of a hassle, you can use single-command proxies in most command-line tools separately.

cURL

With cURL, you can specify the proxy to use with the -x or --proxy options.

curl -x http://PROXY_HOST:PROXY_PORT https://iproyal.com/

Authentication can be added if the proxy requires it.

curl -x http://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT https://iproyal.com/

Wget

The most straightforward way to use proxies with Wget in Ubuntu is to use them for a single line:

wget -e use_proxy=yes -e http_proxy=http://PROXY_HOST:PROXY_PORT https://iproyal.com/

If your network proxy requires authentication:

wget -e use_proxy=yes -e http_proxy=http://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT https://iproyal.com/

Git

For Git, it's easiest to set a proxy globally for all repositories.

git config --global http.proxy http_proxy=http://PROXY_HOST:PROXY_PORT

If your proxy server needs authentication:

git config --global https.proxy http://username:password@proxy_address:proxy_port

Test and Verify Proxy Connection

At least one of the methods to set proxies on Ubuntu should have been suitable for your use case. To test whether proxies work, you can visit a web page that shows your IP address, such as our IP lookup tool, or use a cURL command.

curl https://ifconfig.me

If the IP address you see is of your proxy, then the setup is working.

Share on

Frequently Asked Questions

How do I set a system-wide proxy in Ubuntu?

The easiest way to set a system-wide proxy server in Ubuntu is to use the graphical interface. Simply head to settings and find the network proxy tab. There, you can configure proxy settings and apply a system-wide proxy. Another option is to use a terminal and edit configuration files.

Can I use rotating proxies with Ubuntu?

Of course, you can use rotating proxies with the Ubuntu operating system. One way is to implement scripts that rotate various proxy servers in your own pool. Often, various software solutions for web scraping and automation will include proxy rotation. If that's not the case, you can simply purchase IPRoyal's rotating proxy service.

Does Ubuntu support SOCKS5 proxies?

Yes, Ubuntu proxy integration officially supports SOCKS5 proxies for both temporary and permanent system-wide configurations. The option is available in the graphical interface under Manual Proxy Configuration, and you can use terminal commands, such as export socks5_proxy="socks5://127.0.0.1:1080" for setting up SOCKS5 proxy servers from your provider.