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:
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:
- Open the file:
nano ~/.bashrc
- Add the following lines at the end of the file:
# 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"
- Save and close the file (Ctrl+O, Enter, Ctrl+X in nano)
- Apply the changes:
source ~/.bashrc
System-Wide Proxy Configuration
Using the GUI (Desktop Environment)
Ubuntu provides a graphical interface for configuring proxy settings:
- Open Settings (or System Settings)
- Navigate to Network
- Click on Network Proxy
- 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:
- Open the environment file with sudo privileges:
sudo nano /etc/environment
- Add the following lines:
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"
- Save and close the file
- 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:
- Create or edit the apt.conf file:
sudo nano /etc/apt/apt.conf.d/80proxy
- Add the following lines:
Acquire::http::Proxy "http://username:[email protected]:8080";
Acquire::https::Proxy "http://username:[email protected]:8080";
- 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
:
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:
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:
git config --global --unset http.proxy
git config --global --unset https.proxy
Snap
Configure snap to use a proxy:
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:
- Check current environment variables:
env | grep -i proxy
- Test HTTP connectivity:
curl -I http://www.example.com
- Test with explicit proxy:
curl -x http://username:[email protected]:8080 -I http://www.example.com
Troubleshooting Common Issues
Proxy Not Working
- Verify the proxy server address and port are correct
- Check if authentication is required but not provided
- Ensure the proxy server is operational
- Check for typos in configuration files
Certificate Errors with HTTPS
If you encounter SSL/TLS certificate errors:
# 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:
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:
-
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
- Proxy server:
-
Set up system-wide proxy:
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"
- Configure APT:
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";
- Now you can update your system and access the internet through the corporate proxy:
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
- Configure your Ubuntu system to use a free public proxy server for HTTP traffic only.
- Set up different proxies for different users on the same system.
- Create a script that can toggle proxy settings on and off with a single command.
- 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! :)