终端环境变量
bash、zsh、fish、PowerShell、cmd 的代理变量设置。
大多数命令行工具读取 http_proxy / https_proxy / all_proxy(大小写都有工具使用,建议都设置)。
bash / zsh
export http_proxy=http://127.0.0.1:7898
export https_proxy=http://127.0.0.1:7898
export all_proxy=socks5://127.0.0.1:7898
export HTTP_PROXY=$http_proxy HTTPS_PROXY=$https_proxy ALL_PROXY=$all_proxy
export no_proxy=localhost,127.0.0.1,::1
export NO_PROXY=$no_proxy做成开关函数放进 ~/.zshrc 或 ~/.bashrc:
proxy_on() { export http_proxy=http://127.0.0.1:7898 https_proxy=http://127.0.0.1:7898 all_proxy=socks5://127.0.0.1:7898; export HTTP_PROXY=$http_proxy HTTPS_PROXY=$https_proxy ALL_PROXY=$all_proxy; echo "proxy on"; }
proxy_off() { unset http_proxy https_proxy all_proxy HTTP_PROXY HTTPS_PROXY ALL_PROXY; echo "proxy off"; }Linux 用户可以直接:
eval "$(cnb env)" # 设置
eval "$(cnb env --unset)" # 取消fish
set -gx http_proxy http://127.0.0.1:7898
set -gx https_proxy http://127.0.0.1:7898
set -gx all_proxy socks5://127.0.0.1:7898
# Linux
cnb env --shell fish | sourceWindows PowerShell
$env:HTTP_PROXY = "http://127.0.0.1:7898"
$env:HTTPS_PROXY = "http://127.0.0.1:7898"
$env:NO_PROXY = "localhost,127.0.0.1"Windows cmd
set HTTP_PROXY=http://127.0.0.1:7898
set HTTPS_PROXY=http://127.0.0.1:7898验证
curl -sI https://github.com | head -1