Skip to main content

Ubuntu Proxy Settings

Introduction

Proxy servers act as intermediaries between your computer and the internet. When properly configured, they can provide benefits like improved security, privacy, bandwidth savings, and access to region-restricted content. In corporate or educational environments, proxy servers are often mandatory for internet access.

This guide explains how to configure proxy settings in Ubuntu, covering different methods for system-wide configuration and application-specific settings.

Understanding Proxy Types

Before diving into configuration, it's important to understand the common types of proxies:

  • HTTP Proxy: Handles HTTP traffic (web browsing)
  • HTTPS Proxy: Handles HTTPS encrypted traffic
  • FTP Proxy: Handles File Transfer Protocol traffic
  • SOCKS Proxy: A general-purpose proxy that works with any protocol

Environment Variables Method

The simplest way to configure proxy settings is through environment variables. These can be set temporarily in a terminal session or permanently in configuration files.

Temporary Proxy Settings

To set proxy settings for a current terminal session only:

bash
export http_proxy="http://username:[email protected]:8080"
export https_proxy="http://username:[email protected]:8080"
export ftp_proxy="http://username:[email protected]:8080"
export no_proxy="localhost,127.0.0.1,local.home"

These settings apply only to the current terminal session and will be lost after closing it.

Permanent Proxy Settings

For persistent proxy settings, add them to your ~/.bashrc or ~/.profile file:

  1. Open the file:
bash
nano ~/.bashrc
  1. Add the following lines at the end of the file:
bash
# Proxy Settings
export http_proxy="http://username:[email protected]:8080"
export https_proxy="http://username:[email protected]:8080"
export ftp_proxy="http://username:[email protected]:8080"
export no_proxy="localhost,127.0.0.1,local.home"

# Uppercase variables (some applications use these)
export HTTP_PROXY="http://username:[email protected]:8080"
export HTTPS_PROXY="http://username:[email protected]:8080"
export FTP_PROXY="http://username:[email protected]:8080"
export NO_PROXY="localhost,127.0.0.1,local.home"
  1. Save and close the file (Ctrl+O, Enter, Ctrl+X in nano)
  2. Apply the changes:
bash
source ~/.bashrc

System-Wide Proxy Configuration

Using the GUI (Desktop Environment)

Ubuntu provides a graphical interface for configuring proxy settings:

  1. Open Settings (or System Settings)
  2. Navigate to Network
  3. Click on Network Proxy
  4. Choose the method:
    • Automatic: If your network provides a proxy auto-configuration (PAC) file
    • Manual: To enter proxy details manually
    • None: To disable proxy

For manual configuration, enter your proxy details for each protocol:

Using the /etc/environment File

For system-wide proxy settings that affect all users and many applications:

  1. Open the environment file with sudo privileges:
bash
sudo nano /etc/environment
  1. Add the following lines:
bash
http_proxy="http://username:[email protected]:8080"
https_proxy="http://username:[email protected]:8080"
ftp_proxy="http://username:[email protected]:8080"
no_proxy="localhost,127.0.0.1,local.home"
HTTP_PROXY="http://username:[email protected]:8080"
HTTPS_PROXY="http://username:[email protected]:8080"
FTP_PROXY="http://username:[email protected]:8080"
NO_PROXY="localhost,127.0.0.1,local.home"
  1. Save and close the file
  2. Log out and log back in for the changes to take effect

Application-Specific Proxy Settings

Many applications have their own proxy configurations which override system settings.

APT (Package Manager)

Configure APT to use a proxy:

  1. Create or edit the apt.conf file:
bash
sudo nano /etc/apt/apt.conf.d/80proxy
  1. Add the following lines:
Acquire::http::Proxy "http://username:[email protected]:8080";
Acquire::https::Proxy "http://username:[email protected]:8080";
  1. Save and close the file

After this, APT commands like apt update and apt install will use the proxy.

Wget

For wget, create or edit ~/.wgetrc:

bash
nano ~/.wgetrc

Add the following lines:

use_proxy=yes
http_proxy=http://username:[email protected]:8080
https_proxy=http://username:[email protected]:8080

Git

Configure Git to use a proxy:

bash
git config --global http.proxy http://username:[email protected]:8080
git config --global https.proxy http://username:[email protected]:8080

To remove the proxy settings later:

bash
git config --global --unset http.proxy
git config --global --unset https.proxy

Snap

Configure snap to use a proxy:

bash
sudo snap set system proxy.http="http://username:[email protected]:8080"
sudo snap set system proxy.https="http://username:[email protected]:8080"

Authentication and Special Characters

If your proxy requires authentication with a username and password containing special characters, you'll need to URL-encode them:

For example, if your password is p@ssw0rd!, encode it as p%40ssw0rd%21

A general format is:

http://username:[email protected]:port

With encoded special characters:

http://username:p%40ssw0rd%[email protected]:port

Testing Your Proxy Settings

To verify your proxy settings are working:

  1. Check current environment variables:
bash
env | grep -i proxy
  1. Test HTTP connectivity:
bash
curl -I http://www.example.com
  1. Test with explicit proxy:
bash
curl -x http://username:[email protected]:8080 -I http://www.example.com

Troubleshooting Common Issues

Proxy Not Working

  1. Verify the proxy server address and port are correct
  2. Check if authentication is required but not provided
  3. Ensure the proxy server is operational
  4. Check for typos in configuration files

Certificate Errors with HTTPS

If you encounter SSL/TLS certificate errors:

bash
# Try adding the -k flag to curl for testing
curl -k -x https://proxy.example.com:8080 https://example.com

# For a permanent fix, you might need to import certificates
sudo cp company-certificate.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates

Application Still Not Using Proxy

Some applications ignore environment variables. Check the application's documentation for specific proxy configuration.

Disabling Proxy Settings

To temporarily disable proxy settings:

bash
unset http_proxy https_proxy ftp_proxy no_proxy
unset HTTP_PROXY HTTPS_PROXY FTP_PROXY NO_PROXY

To permanently disable them, remove or comment out the settings in the configuration files mentioned above.

Real-World Example: Corporate Network Setup

Let's walk through a complete example for a user in a corporate environment:

  1. Your IT department provides these details:

    • Proxy server: proxy.company.com
    • Port: 8080
    • Username: employee
    • Password: Corp@2023
    • No proxy needed for internal sites: .company.local, 192.168.0.0/16
  2. Set up system-wide proxy:

bash
sudo nano /etc/environment

Add:

http_proxy="http://employee:Corp%[email protected]:8080"
https_proxy="http://employee:Corp%[email protected]:8080"
no_proxy="localhost,127.0.0.1,.company.local,192.168.0.0/16"
HTTP_PROXY="http://employee:Corp%[email protected]:8080"
HTTPS_PROXY="http://employee:Corp%[email protected]:8080"
NO_PROXY="localhost,127.0.0.1,.company.local,192.168.0.0/16"
  1. Configure APT:
bash
sudo nano /etc/apt/apt.conf.d/80proxy

Add:

Acquire::http::Proxy "http://employee:Corp%[email protected]:8080";
Acquire::https::Proxy "http://employee:Corp%[email protected]:8080";
  1. Now you can update your system and access the internet through the corporate proxy:
bash
sudo apt update

Summary

Ubuntu offers multiple ways to configure proxy settings, from temporary environment variables to permanent system-wide configurations. The method you choose depends on your specific needs:

  • Use environment variables for quick, user-specific settings
  • Use /etc/environment for system-wide settings
  • Configure individual applications when necessary
  • Use the GUI for desktop users who prefer graphical interfaces

Remember to URL-encode special characters in usernames and passwords, and to test your configuration to ensure it's working properly.

Additional Resources

Exercises

  1. Configure your Ubuntu system to use a free public proxy server for HTTP traffic only.
  2. Set up different proxies for different users on the same system.
  3. Create a script that can toggle proxy settings on and off with a single command.
  4. Configure a browser like Firefox to use a different proxy than the system-wide settings.


If you spot any mistakes on this website, please let me know at [email protected]. I’d greatly appreciate your feedback! :)