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.
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
| Item | Description |
|---|---|
| Proxy address | e.g. proxy.16yun.cn |
| Port number | e.g. 8888 (HTTP), 1080 (SOCKS5) |
| Authentication | Username/password (if required) |
| Protocol type | HTTP, 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,::1Permanent (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-ngConfiguration: Edit /etc/proxychains4.conf:
[ProxyList]
http proxy.16yun.cn 8888
# socks5 proxy.16yun.cn 1080Usage:
proxychains4 curl https://httpbin.org/ip
proxychains4 python3 my_script.pyMethod 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.confGit:
git config --global http.proxy http://proxy.16yun.cn:8888
git config --global https.proxy http://proxy.16yun.cn:8888Docker:
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"
}
}
}
EOFProxy Protocol Overview
| Protocol | Layer | Supported Traffic |
|---|---|---|
| HTTP proxy | Application | HTTP/HTTPS only |
| HTTPS proxy | Application | Encrypted HTTP tunnel |
| SOCKS5 proxy | Transport | TCP and UDP |
Authentication Methods
| Method | Example |
|---|---|
| Username/password | http://user:pass@proxy.16yun.cn:8888 |
| IP whitelist | No credentials needed |
| Token authentication | http://token@proxy.16yun.cn:8888 |
Security Tips
- Do not hardcode passwords in scripts. Store credentials in a config file with
chmod 600. - Use
sudo -Eto preserve proxy variables:sudo -E apt update. - Verify proxy anonymity via httpbin.org/ip.
- Prefer HTTPS proxies when transmitting sensitive data.
Distribution Differences
| Distribution | Package Manager | Proxy Config |
|---|---|---|
| Ubuntu / Debian | apt | /etc/apt/apt.conf.d/proxy.conf |
| CentOS / RHEL | yum / dnf | /etc/yum.conf |
| Arch Linux | pacman | /etc/pacman.conf |
Verification
curl -s https://httpbin.org/ipThe 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.pysystemd 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
| Method | Scope | Persistence | Complexity |
|---|---|---|---|
| Terminal export | Current session | Temporary | Low |
| Shell profile | All terminals | Permanent | Low |
| proxychains | Per-command | Per use | Medium |
| Tool config | Single tool | Permanent | Medium |
| systemd service | Single service | Permanent | High |
Common Use Cases
| Scenario | Recommended Method |
|---|---|
| Quick test | export in terminal |
| Daily development | export in ~/.bashrc |
| Legacy tools | proxychains |
| System services | systemd Environment |
| Automated pipelines | Per-tool config |
Related Guides
- 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.