Note: Linux Proxy Settings

Published on

Original language: Chinese . AI translations: English , Japanese .


Proxy configuration on Linux.

Ref

Proxy server - ArchWiki
Environment variables - ArchWiki
These two docs basically cover most proxy-related issues on Linux.

How To Use Proxy Server To Access Internet at Shell Prompt With http_proxy Variable
This one is a simpler “just do it” guide.


I read a bunch of tutorials before and still didn’t get it.
In the end, good documentation is the most reliable.


2019/12/23 update

  • Set proxy via environment variables
    Add to ~/.bashrc:
Terminal window
export http_proxy=http://<proxy_addr>:<proxy_port>/
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
Terminal window
Defaults env_keep += "ftp_proxy http_proxy https_proxy no_proxy"

2021/02/24 update
It’s better not to edit sudoers directly. Add a file under /etc/sudoers.d/ instead.

Terminal window
$ sudo visudo /etc/sudoers.d/env_proxy
Add following line
Defaults env_keep += "ftp_proxy http_proxy https_proxy no_proxy"

Ref:adding local content in /etc/sudoers.d/ instead of directly modifying sodoers file via visudo

2021/05/09 update

Terminal window
vim /etc/sudoers.d/05_proxy
Defaults env_keep += "*_proxy *_PROXY"

Ref: ArchWiki - Proxy server: Keep proxy through sudo

Terminal window
sudo snap set system proxy.http="http://<proxy_addr>:<proxy_port>"
sudo snap set system proxy.https="http://<proxy_addr>:<proxy_port>"
Terminal window
sudo visudo
For Ubuntu 14, you need to specify in separate lines as it returns the errors for multi-variable lines:
Defaults env_keep += "http_proxy"
Defaults env_keep += "https_proxy"
Defaults env_keep += "HTTP_PROXY"
Defaults env_keep += "HTTPS_PROXY"

2021/04/10 update

curl and pacman

Ref: ArchWiki - Proxy server: crul and pacman

You may set the all_proxy environment variable to let curl and pacman (which uses curl) use your socks5 proxy:
$ export all_proxy="socks5://your.proxy:1080"