Ithy Logo

Comprehensive Guide to Configuring a Global Proxy in Ubuntu

Ensure all your applications use a single proxy configuration seamlessly

ubuntu server configuration

Key Takeaways

  • Unified Configuration: Setting environment variables in system files ensures all applications default to the proxy without individual setups.
  • APT and Systemd Integration: Properly configuring APT and systemd ensures package managers and services adhere to the proxy settings.
  • Verification and Troubleshooting: Testing configurations with tools like curl and wget, alongside troubleshooting common issues, guarantees a smooth proxy setup.

Introduction

Configuring a global proxy in Ubuntu allows all your system applications, including apt, wget, and curl, to route their traffic through a specified proxy server. This setup eliminates the need for individual proxy configurations across different applications, ensuring consistent network settings and simplifying administrative tasks.


Step-by-Step Guide to Configure a Global Proxy in Ubuntu

1. Setting System-Wide Proxy Using Environment Variables

Environment variables are central to setting system-wide proxy configurations that apply to all users and applications.

a. Edit the /etc/environment File

  1. Open the File with Root Privileges:
    sudo nano /etc/environment
  2. Add Proxy Variables:

    Insert the following lines, replacing username, password, proxy_address, and proxy_port with your proxy details.

    
    http_proxy="http://username:password@proxy_address:proxy_port/"
    https_proxy="https://username:password@proxy_address:proxy_port/"
    ftp_proxy="ftp://username:password@proxy_address:proxy_port/"
    no_proxy="localhost,127.0.0.1,::1"
    HTTP_PROXY="http://username:password@proxy_address:proxy_port/"
    HTTPS_PROXY="http://username:password@proxy_address:proxy_port/"
    FTP_PROXY="http://username:password@proxy_address:proxy_port/"
    NO_PROXY="localhost,127.0.0.1,::1"
                

    Note: Including both lowercase and uppercase variables ensures compatibility with different applications.

  3. Save and Exit: Press Ctrl+O to save and Ctrl+X to exit the editor.
  4. Apply the Changes:
    source /etc/environment

    Alternatively, you can log out and log back in or reboot your system to apply the changes.

2. Configuring APT to Use the Proxy

The Advanced Package Tool (APT) doesn't automatically inherit the environment proxy settings. You need to configure it separately to ensure package management operations use the proxy.

a. Create or Edit the APT Proxy Configuration File

  1. Create the Configuration File:
    sudo nano /etc/apt/apt.conf.d/95proxies
  2. Add Proxy Settings:
    
    Acquire::http::Proxy "http://username:password@proxy_address:proxy_port/";
    Acquire::https::Proxy "https://username:password@proxy_address:proxy_port/";
    Acquire::ftp::Proxy "ftp://username:password@proxy_address:proxy_port/";
                
  3. Save and Exit: Press Ctrl+O to save and Ctrl+X to exit.

3. Configuring Systemd to Use the Proxy

Systemd services require explicit proxy configurations to adhere to the global proxy settings.

a. Edit the Systemd Configuration File

  1. Open the File:
    sudo nano /etc/systemd/system.conf
  2. Add Proxy Environment Variables:

    Under the [Manager] section, add:

    DefaultEnvironment="HTTP_PROXY=http://username:password@proxy_address:proxy_port/" "HTTPS_PROXY=http://username:password@proxy_address:proxy_port/" "NO_PROXY=localhost,127.0.0.1,::1"
  3. Save and Exit: Press Ctrl+O to save and Ctrl+X to exit.
  4. Reload Systemd Daemon:
    sudo systemctl daemon-reload
  5. Reboot the System:
    sudo reboot

4. Configuring Proxy for Command-Line Tools

a. For Wget

  1. Edit the ~/.wgetrc File:
    sudo nano ~/.wgetrc
  2. Add Proxy Settings:
    
    http_proxy = http://username:password@proxy_address:proxy_port/
    https_proxy = http://username:password@proxy_address:proxy_port/
    ftp_proxy = http://username:password@proxy_address:proxy_port/
                
  3. Save and Exit: Press Ctrl+O to save and Ctrl+X to exit.

b. For Curl

  1. Edit the Shell Configuration File:
    nano ~/.bashrc
  2. Add Proxy Environment Variables:
    
    export http_proxy="http://username:password@proxy_address:proxy_port/"
    export https_proxy="https://username:password@proxy_address:proxy_port/"
    export ftp_proxy="ftp://username:password@proxy_address:proxy_port/"
    export no_proxy="localhost,127.0.0.1,::1"
                
  3. Save and Exit: Press Ctrl+O to save and Ctrl+X to exit.
  4. Apply the Changes:
    source ~/.bashrc

5. Configuring Proxy for GUI Applications

For desktop environments, configuring the proxy through the GUI ensures that applications relying on GNOME settings use the proxy.

a. Using the Ubuntu Settings Interface

  1. Open System Settings:

    Navigate to Settings > Network > Network Proxy.

  2. Set Proxy Details:
    1. Select Manual configuration.
    2. Enter the proxy details for HTTP, HTTPS, and FTP.
    3. Click Apply System-Wide to enforce the settings.

6. Making Proxy Settings Persistent

Ensuring that proxy configurations persist across system reboots and user sessions is crucial for consistent network behavior.

a. Create a Proxy Script

  1. Create the Script File:
    sudo nano /etc/profile.d/proxy.sh
  2. Add Export Statements:
    
    export http_proxy="http://username:password@proxy_address:proxy_port/"
    export https_proxy="https://username:password@proxy_address:proxy_port/"
    export ftp_proxy="ftp://username:password@proxy_address:proxy_port/"
    export no_proxy="localhost,127.0.0.1,::1"
                
  3. Make the Script Executable:
    sudo chmod +x /etc/profile.d/proxy.sh
  4. Apply the Changes Immediately:
    source /etc/profile.d/proxy.sh

7. Testing the Proxy Configuration

Verifying that the proxy settings are correctly applied ensures that all applications route their traffic through the proxy.

a. Test with Curl

curl -I http://example.com

b. Test with Wget

wget http://example.com

c. Test APT

sudo apt update

Successful execution of these commands without proxy-related errors indicates a correctly configured global proxy.


8. Troubleshooting Common Issues

  • Verify Proxy Reachability: Ensure that the proxy server is accessible from your machine.

  • Check for Typographical Errors: Even minor mistakes in configuration files can prevent the proxy from functioning correctly.

  • Confirm Environment Variables: Use the env | grep -i proxy command to verify that proxy variables are set correctly.

  • Review File Permissions: Ensure that the proxy script files are executable and owned by the correct user.

  • Inspect Application-Specific Settings: Some applications might have their own proxy settings that override system configurations.


Recap

Configuring a global proxy in Ubuntu involves setting environment variables, configuring APT and systemd, and ensuring GUI applications adhere to the proxy settings. By following the steps outlined above, you can ensure a unified proxy configuration across all applications, simplifying network management and enhancing security.

References


Last updated January 23, 2025
Search Again