How to Configure System-Wide Proxy Settings in Ubuntu Server 10.04 Beta 2 via Command Line


2 views

When working with Ubuntu Server 10.04 Beta 2 (Lucid Lynx), you might need to configure system-wide proxy settings for package managers, wget, curl, and other command-line tools. Unlike desktop editions, the server version requires manual configuration through terminal commands.

The most straightforward way is setting environment variables in your shell configuration:

# Temporary session-only configuration
export http_proxy="http://proxy.example.com:3128"
export https_proxy="http://proxy.example.com:3128"
export ftp_proxy="http://proxy.example.com:3128"

For permanent configuration, add these lines to ~/.bashrc or /etc/environment:

# Persistent configuration
echo 'http_proxy="http://proxy.example.com:3128"' | sudo tee -a /etc/environment
echo 'https_proxy="http://proxy.example.com:3128"' | sudo tee -a /etc/environment
echo 'ftp_proxy="http://proxy.example.com:3128"' | sudo tee -a /etc/environment

For Ubuntu's package management system, create or edit /etc/apt/apt.conf.d/80proxy:

Acquire::http::Proxy "http://proxy.example.com:3128";
Acquire::https::Proxy "http://proxy.example.com:3128";
Acquire::ftp::Proxy "http://proxy.example.com:3128";

To make sudo respect your proxy settings, edit /etc/sudoers with visudo:

Defaults env_keep += "http_proxy https_proxy ftp_proxy"

Verify your settings with these commands:

# Check environment variables
env | grep -i proxy

# Test HTTP connectivity
curl -I http://ubuntu.com

# Test HTTPS connectivity
curl -I https://ubuntu.com

# Test APT proxy
sudo apt-get update

If your network uses a PAC file, you'll need additional tools:

sudo apt-get install libproxy-tools

# Create proxy configuration
echo 'export PROXY_Method=auto' | sudo tee -a /etc/environment
echo 'export PROXY_AutoConfig_URL=http://your-proxy/config.pac' | sudo tee -a /etc/environment

If you encounter problems:

# Check if proxy is reachable
nc -zv proxy.example.com 3128

# View active environment variables
printenv

# Check system logs for proxy-related errors
grep -i proxy /var/log/syslog

Some applications may need individual proxy settings:

# For wget
echo "use_proxy = on" >> ~/.wgetrc
echo "http_proxy = http://proxy.example.com:3128" >> ~/.wgetrc

# For git
git config --global http.proxy http://proxy.example.com:3128

When working with Ubuntu Server (especially 10.4 beta 2), there are multiple layers where proxy settings can be configured:

1. System-wide environment variables
2. APT package manager configuration
3. NetworkManager settings (though minimal in server edition)
4. Application-specific configurations

The most fundamental way to set system-wide proxies is through environment variables. Add these lines to /etc/environment:

http_proxy="http://proxy.example.com:8080/"
https_proxy="http://proxy.example.com:8080/"
ftp_proxy="http://proxy.example.com:8080/"
no_proxy="localhost,127.0.0.1,::1,.internal.example.com"

To apply immediately without reboot:

source /etc/environment
export $(cat /etc/environment | xargs)

For package management operations, create/edit /etc/apt/apt.conf.d/02proxy:

Acquire::http::Proxy "http://proxy.example.com:8080";
Acquire::https::Proxy "http://proxy.example.com:8080";
Acquire::ftp::Proxy "http://proxy.example.com:8080";

For services managed by systemd, create a drop-in directory:

sudo mkdir -p /etc/systemd/system/service_name.service.d/
sudo nano /etc/systemd/system/service_name.service.d/proxy.conf

Add this content (replace service_name with actual service):

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080"
Environment="HTTPS_PROXY=http://proxy.example.com:8080"
Environment="NO_PROXY=localhost,127.0.0.1"

Then reload systemd:

sudo systemctl daemon-reload
sudo systemctl restart service_name

Check if variables are properly set:

env | grep -i proxy
curl -v http://example.com  # Check if going through proxy
sudo apt update             # Test package manager

For repeatable deployments, create a setup script:

#!/bin/bash
PROXY="http://proxy.example.com:8080"
NOPROXY="localhost,127.0.0.1"

# Environment
echo "http_proxy=\"$PROXY\"" | sudo tee -a /etc/environment
echo "no_proxy=\"$NOPROXY\"" | sudo tee -a /etc/environment

# APT
echo "Acquire::http::Proxy \"$PROXY\";" | sudo tee /etc/apt/apt.conf.d/02proxy

# Systemd services
for service in docker.service apt-cacher-ng.service; do
  sudo mkdir -p "/etc/systemd/system/$service.d/"
  echo "[Service]" | sudo tee "/etc/systemd/system/$service.d/proxy.conf"
  echo "Environment=\"HTTP_PROXY=$PROXY\"" | sudo tee -a "/etc/systemd/system/$service.d/proxy.conf"
done

sudo systemctl daemon-reload

Make script executable and run:

chmod +x proxy_setup.sh
sudo ./proxy_setup.sh