Skip to content

Complete Linux Proxy Configuration Guide - curl, wget, Docker, yum Support

Key Points

By reading this article, you can completely master the following proxy settings:

  • System-wide proxy settings - Comprehensive configuration using environment variables
  • Command-line tools - Individual settings for curl, wget, ssh, git
  • Package managers - Package management via proxy for yum, dnf, apt
  • Container environment - Proxy settings for Docker containers and image builds
  • Development tools - Proxy settings for development environments like npm, pip, brew

System-wide Proxy Settings

Basic Configuration Using Environment Variables

Add to ~/.bashrc or ~/.zshrc:

# HTTP/HTTPS proxy settings
export http_proxy="http://proxy.company.com:8080"
export https_proxy="http://proxy.company.com:8080"
export ftp_proxy="http://proxy.company.com:8080"

# With authentication
export http_proxy="http://USER:PASS@proxy.company.com:8080"
export https_proxy="http://USER:PASS@proxy.company.com:8080"

# Hosts that don't use proxy (comma-separated)
export no_proxy="localhost,127.0.0.1,*.company.com,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"

# Uppercase versions (required by some applications)
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$https_proxy
export FTP_PROXY=$ftp_proxy
export NO_PROXY=$no_proxy

System-wide configuration (/etc/environment):

http_proxy="http://proxy.company.com:8080"
https_proxy="http://proxy.company.com:8080"
ftp_proxy="http://proxy.company.com:8080"
no_proxy="localhost,127.0.0.1,*.company.com"

Temporary Proxy Settings

# Current session only
export http_proxy="http://proxy.company.com:8080"

# Specific command only
http_proxy="http://proxy.company.com:8080" curl https://example.com

# Disable proxy
unset http_proxy https_proxy ftp_proxy

Command-line Tool Proxy Settings

curl

# Command-line options
curl --proxy http://proxy.company.com:8080 https://example.com
curl -x proxy.company.com:8080 https://example.com

# Proxy with authentication
curl --proxy-user USER:PASS --proxy http://proxy.company.com:8080 https://example.com

# No proxy
curl --noproxy "*.company.com,localhost" https://internal.company.com

# SOCKS5 proxy
curl --socks5 proxy.company.com:1080 https://example.com

# Configuration in ~/.curlrc
echo 'proxy = "http://proxy.company.com:8080"' >> ~/.curlrc

wget

# Command-line options
wget --proxy=on --http-proxy=http://proxy.company.com:8080 https://example.com

# Configuration via environment variables (recommended)
export http_proxy="http://proxy.company.com:8080"
wget https://example.com

# Configuration in ~/.wgetrc
cat >> ~/.wgetrc << EOF
http_proxy = http://proxy.company.com:8080
https_proxy = http://proxy.company.com:8080
ftp_proxy = http://proxy.company.com:8080
use_proxy = on
EOF

# No proxy
wget --no-proxy https://internal.company.com

git

# Proxy settings for HTTPS repositories
git config --global http.proxy http://proxy.company.com:8080
git config --global https.proxy http://proxy.company.com:8080

# Use proxy only for specific URLs
git config --global http.https://github.com.proxy http://proxy.company.com:8080

# Proxy settings for SSH connections (~/.ssh/config)
cat >> ~/.ssh/config << EOF
Host github.com
    User git
    ProxyCommand nc -X connect -x proxy.company.com:8080 %h %p
EOF

# Remove proxy settings
git config --global --unset http.proxy
git config --global --unset https.proxy

ssh

# Configuration in ~/.ssh/config
cat >> ~/.ssh/config << EOF
Host target-server
    ProxyCommand nc -X connect -x proxy.company.com:8080 %h %p

# Via HTTP proxy
Host target-server  
    ProxyCommand corkscrew proxy.company.com 8080 %h %p
EOF

# Command-line specification
ssh -o ProxyCommand="nc -X connect -x proxy.company.com:8080 %h %p" user@target-server

Package Manager Proxy Settings

yum / dnf (RHEL/CentOS/Fedora)

RHEL 8 and later (/etc/dnf/dnf.conf):

[main]
proxy=http://proxy.company.com:8080
proxy_username=username
proxy_password=password

RHEL 7 and earlier (/etc/yum.conf):

[main]
proxy=http://proxy.company.com:8080
proxy_username=username
proxy_password=password

Subscription Manager settings (/etc/rhsm/rhsm.conf):

[server]
proxy_hostname = proxy.company.com
proxy_port = 8080
proxy_user = username
proxy_password = password

apt (Ubuntu/Debian)

/etc/apt/apt.conf.d/95proxies:

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

# With authentication
Acquire::http::Proxy "http://USER:PASS@proxy.company.com:8080/";

# No proxy for specific hosts
Acquire::http::Proxy::ppa.launchpad.net "DIRECT";

Temporary configuration:

sudo apt -o Acquire::http::Proxy="http://proxy.company.com:8080" update

zypper (openSUSE)

# Proxy settings
sudo zypper modifyrepo --proxy http://proxy.company.com:8080 --all

# Edit configuration file (/etc/zypp/zypp.conf)
proxy = http://proxy.company.com:8080
proxyuser = username
proxypass = password

Docker Environment Proxy Settings

Docker Daemon Proxy Settings

/etc/systemd/system/docker.service.d/http-proxy.conf:

[Service]
Environment="HTTP_PROXY=http://proxy.company.com:8080"
Environment="HTTPS_PROXY=http://proxy.company.com:8080"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.company.com"

Apply settings:

sudo systemctl daemon-reload
sudo systemctl restart docker

Proxy Settings for Container Runtime

# Specify via environment variables
docker run -e http_proxy=http://proxy.company.com:8080 \
           -e https_proxy=http://proxy.company.com:8080 \
           -e no_proxy=localhost,127.0.0.1 \
           ubuntu:latest

# Docker Compose configuration
version: '3'
services:
  app:
    image: ubuntu:latest
    environment:
      - http_proxy=http://proxy.company.com:8080
      - https_proxy=http://proxy.company.com:8080
      - no_proxy=localhost,127.0.0.1

Proxy Settings for Docker Build

# Proxy settings in Dockerfile
FROM ubuntu:latest

# Receive as build arguments
ARG http_proxy
ARG https_proxy
ARG no_proxy

# Set as environment variables
ENV http_proxy=${http_proxy}
ENV https_proxy=${https_proxy}
ENV no_proxy=${no_proxy}

RUN apt-get update && apt-get install -y curl

Build execution:

docker build --build-arg http_proxy=http://proxy.company.com:8080 \
             --build-arg https_proxy=http://proxy.company.com:8080 \
             --build-arg no_proxy=localhost,127.0.0.1 \
             -t myapp .

Configuration in ~/.docker/config.json

{
  "proxies": {
    "default": {
      "httpProxy": "http://proxy.company.com:8080",
      "httpsProxy": "http://proxy.company.com:8080",
      "noProxy": "localhost,127.0.0.1,docker-registry.company.com"
    }
  }
}

Development Tool Proxy Settings

npm (Node.js)

# Proxy settings
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

# Registry-specific settings
npm config set @company:registry https://npm.company.com/
npm config set //npm.company.com/:_authToken "auth-token"

# Bypass SSL certificate errors (development environment only)
npm config set strict-ssl false

# Check settings
npm config list

# Delete settings
npm config delete proxy
npm config delete https-proxy

pip (Python)

~/.pip/pip.conf:

[global]
proxy = http://proxy.company.com:8080
trusted-host = pypi.org
               pypi.python.org
               files.pythonhosted.org

Configuration via environment variables:

export pip_proxy=http://proxy.company.com:8080
pip install --proxy $pip_proxy package-name

# Temporary configuration
pip install --proxy http://proxy.company.com:8080 requests

Homebrew (macOS)

# Execute after setting environment variables
export ALL_PROXY=http://proxy.company.com:8080
brew update

# Git configuration also required (Homebrew uses git)
git config --global http.proxy http://proxy.company.com:8080

Maven (Java)

~/.m2/settings.xml:

<settings>
  <proxies>
    <proxy>
      <id>company-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.company.com</host>
      <port>8080</port>
      <username>username</username>
      <password>password</password>
      <nonProxyHosts>localhost|127.0.0.1|*.company.com</nonProxyHosts>
    </proxy>
  </proxies>
</settings>

Gradle (Java)

gradle.properties:

systemProp.http.proxyHost=proxy.company.com
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=username
systemProp.http.proxyPassword=password

systemProp.https.proxyHost=proxy.company.com
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=username
systemProp.https.proxyPassword=password

systemProp.http.nonProxyHosts=*.company.com|localhost|127.0.0.1

Connection Verification and Testing

Basic Connection Test

# HTTP connection test
curl -I --proxy http://proxy.company.com:8080 http://httpbin.org/ip
curl -I --proxy http://proxy.company.com:8080 https://httpbin.org/ip

# Check IP address via proxy
curl --proxy http://proxy.company.com:8080 https://httpbin.org/ip

# Check without proxy (for comparison)
curl https://httpbin.org/ip

# DNS resolution test
nslookup google.com
dig google.com

# Port connection test
telnet proxy.company.com 8080
nc -zv proxy.company.com 8080

Package Manager Testing

# yum/dnf
dnf repolist                    # RHEL 8 and later
yum repolist                    # RHEL 7 and earlier
dnf search vim                  # RHEL 8 and later
yum search vim                  # RHEL 7 and earlier

# apt
apt update
apt search curl

# Check connection logs
tail -f /var/log/dnf.log        # RHEL 8 and later
tail -f /var/log/yum.log        # RHEL 7 and earlier
tail -f /var/log/apt/history.log # Ubuntu/Debian

Docker Connection Test

# Image pull test
docker pull hello-world

# Container test via proxy
docker run --rm -e http_proxy=$http_proxy alpine:latest \
  sh -c "apk update && apk add curl && curl -I https://httpbin.org/ip"

Troubleshooting

Common Issues and Solutions

1. SSL Certificate Errors

# curl
curl -k https://example.com  # Skip SSL certificate verification

# wget
wget --no-check-certificate https://example.com

# Environment variables
export PYTHONHTTPSVERIFY=0  # Python requests
export NODE_TLS_REJECT_UNAUTHORIZED=0  # Node.js (development environment only)

2. Special Character Errors with Authentication Proxy

# When URL encoding is required
# @ → %40, : → %3A, % → %25
export http_proxy="http://user%40domain.com:pass%40word@proxy.company.com:8080"

3. Proxy Auto-Detection (PAC) Environment

# Check PAC file URL
env | grep -i pac

# Manually check proxy server
curl -I http://wpad.company.com/wpad.dat

4. Cache-Related Issues

# Clear yum/dnf cache
dnf clean all && dnf makecache  # RHEL 8 and later
yum clean all && yum makecache  # RHEL 7 and earlier

# Clear apt cache
apt clean && apt update

# Clear Docker cache
docker system prune -a

5. Log Verification

# System logs
journalctl -u systemd-resolved  # DNS resolution
journalctl -u docker            # Docker

# Application logs
tail -f /var/log/squid/access.log      # Squid proxy
tail -f /var/log/rhsm/rhsm.log         # RHEL Subscription Manager

Debug Commands

# Check environment variables
env | grep -i proxy

# Check network settings
ip route show
cat /etc/resolv.conf

# Check connection to proxy server
telnet proxy.company.com 8080

# Check HTTP request details
curl -v --proxy http://proxy.company.com:8080 https://httpbin.org/ip

# Check packets with tcpdump
sudo tcpdump -i any host proxy.company.com

# Check connection status with netstat
netstat -an | grep :8080
ss -tuln | grep :8080

Security Considerations

Secure Management of Authentication Information

# Separate authentication information from environment variables
# Save in ~/.proxy_auth file (permission 600)
echo "USER:PASS" > ~/.proxy_auth
chmod 600 ~/.proxy_auth

# Reference in proxy settings
export http_proxy="http://$(cat ~/.proxy_auth)@proxy.company.com:8080"

# Temporary authentication input
read -s PROXY_PASS
export http_proxy="http://username:${PROXY_PASS}@proxy.company.com:8080"

Appropriate Proxy Bypass Settings

# Don't route internal network through proxy
export no_proxy="localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,*.company.com,.local"

# Also bypass Docker internal communication
export no_proxy="${no_proxy},docker-registry.company.com,*.docker.internal"

Summary

With this complete guide, you can efficiently configure proxy settings in Linux environments. From basic environment variable settings to individual tool configurations, this guide covers all proxy settings that engineers encounter daily.

Key points for configuration: - Use environment variables for global settings as the foundation - Manage authentication information with security in mind - Properly configure bypass settings for internal networks - Utilize log verification and debugging methods for troubleshooting

Regularly perform connection tests to ensure proxy settings are functioning properly.