2025 Linux Terminal Proxy Setup Guide (export + proxychains + apt)

Complete 2025 Linux proxy setup guide covering terminal environment variables, proxychains force proxy, and per-tool proxy configuration.

16Yun Engineering TeamMay 25, 20253 min read

When to Use This

In 2025, Linux remains the dominant platform for servers and development environments. Configuring a proxy on Linux is essential for many scenarios: running data collection tasks on cloud servers that route traffic through proxy IPs, setting up development environments that access external APIs via a proxy, and connecting to external network resources from within a corporate intranet.

Note: Linux offers flexible proxy configuration methods — environment variables, per-tool settings, and system-wide tools like proxychains. This guide covers the most common approaches.

Prerequisites

ItemDescription
Proxy addresse.g. proxy.16yun.cn
Port numbere.g. 8888 (HTTP), 1080 (SOCKS5)
AuthenticationUsername/password (if required)
Protocol typeHTTP, HTTPS, or SOCKS5

Method 1: Environment Variables (Most Common)

Setting http_proxy and https_proxy tells command-line tools like curl and wget to route through the proxy.

Temporary (current session):

export http_proxy=http://proxy.16yun.cn:8888
export https_proxy=http://proxy.16yun.cn:8888
export HTTP_PROXY=http://proxy.16yun.cn:8888
export HTTPS_PROXY=http://proxy.16yun.cn:8888
export no_proxy=localhost,127.0.0.1,::1

Permanent (recommended): Add the exports to ~/.bashrc or ~/.zshrc, then source ~/.bashrc.

Method 2: proxychains — Force Proxy on Any Program

proxychains intercepts network calls from any program and forces them through a proxy, even those without built-in proxy support.

Installation:

# Ubuntu / Debian
sudo apt install proxychains4
# CentOS / RHEL
sudo yum install proxychains-ng

Configuration: Edit /etc/proxychains4.conf:

[ProxyList]
http proxy.16yun.cn 8888
# socks5 proxy.16yun.cn 1080

Usage:

proxychains4 curl https://httpbin.org/ip
proxychains4 python3 my_script.py

Method 3: Per-Tool Configuration

Some tools have their own proxy settings and do not inherit terminal environment variables.

apt:

# Temporary
sudo apt -o Acquire::http::Proxy=http://proxy.16yun.cn:8888 update
# Permanent
echo 'Acquire::http::Proxy "http://proxy.16yun.cn:8888";' | sudo tee /etc/apt/apt.conf.d/proxy.conf

Git:

git config --global http.proxy http://proxy.16yun.cn:8888
git config --global https.proxy http://proxy.16yun.cn:8888

Docker:

mkdir -p ~/.docker && cat > ~/.docker/config.json <<EOF
{
  "proxies": {
    "default": {
      "httpProxy": "http://proxy.16yun.cn:8888",
      "httpsProxy": "http://proxy.16yun.cn:8888",
      "noProxy": "localhost,127.0.0.1"
    }
  }
}
EOF

Proxy Protocol Overview

ProtocolLayerSupported Traffic
HTTP proxyApplicationHTTP/HTTPS only
HTTPS proxyApplicationEncrypted HTTP tunnel
SOCKS5 proxyTransportTCP and UDP

Authentication Methods

MethodExample
Username/passwordhttp://user:pass@proxy.16yun.cn:8888
IP whitelistNo credentials needed
Token authenticationhttp://token@proxy.16yun.cn:8888

Security Tips

  1. Do not hardcode passwords in scripts. Store credentials in a config file with chmod 600.
  2. Use sudo -E to preserve proxy variables: sudo -E apt update.
  3. Verify proxy anonymity via httpbin.org/ip.
  4. Prefer HTTPS proxies when transmitting sensitive data.

Distribution Differences

DistributionPackage ManagerProxy Config
Ubuntu / Debianapt/etc/apt/apt.conf.d/proxy.conf
CentOS / RHELyum / dnf/etc/yum.conf
Arch Linuxpacman/etc/pacman.conf

Verification

curl -s https://httpbin.org/ip

The response should show the proxy IP rather than your own.

Common Issues

Issue 1: Programs ignore the proxy after export

Set both lowercase and uppercase variants (http_proxy and HTTP_PROXY) for compatibility.

Issue 2: proxychains does not work

Verify the address and port. Set proxy_dns = off if DNS resolution fails.

Issue 3: apt update is slow or fails

Include credentials in the proxy URL if required: Acquire::http::Proxy "http://user:pass@proxy.16yun.cn:8888";.

Issue 4: sudo clears proxy settings

Use sudo -E to preserve environment variables.

Proxy for System Services

crontab: Declare proxy variables directly in the crontab:

http_proxy=http://proxy.16yun.cn:8888
https_proxy=http://proxy.16yun.cn:8888
0 2 * * * /usr/bin/python3 /home/user/collect_data.py

systemd services: Add to the service unit, then systemctl daemon-reload && systemctl restart <service>:

[Service]
Environment="http_proxy=http://proxy.16yun.cn:8888"
Environment="https_proxy=http://proxy.16yun.cn:8888"

Quick Comparison

MethodScopePersistenceComplexity
Terminal exportCurrent sessionTemporaryLow
Shell profileAll terminalsPermanentLow
proxychainsPer-commandPer useMedium
Tool configSingle toolPermanentMedium
systemd serviceSingle servicePermanentHigh

Common Use Cases

ScenarioRecommended Method
Quick testexport in terminal
Daily developmentexport in ~/.bashrc
Legacy toolsproxychains
System servicessystemd Environment
Automated pipelinesPer-tool config
  • macOS proxy setup guide
  • Windows proxy setup guide
  • Proxy client software guide

Need an enterprise proxy plan?

We can tailor architecture to your target domains, concurrency, and reliability goals.