367 字
2 分钟
终端代理与 curl / wget 配置速查
这篇用来复制终端代理相关命令。
临时设置终端代理
HTTP 代理:
export http_proxy=http://127.0.0.1:10808export https_proxy=http://127.0.0.1:10808export HTTP_PROXY=http://127.0.0.1:10808export HTTPS_PROXY=http://127.0.0.1:10808SOCKS5 代理:
export all_proxy=socks5://127.0.0.1:10808export ALL_PROXY=socks5://127.0.0.1:10808常见组合:
export http_proxy=http://127.0.0.1:10808export https_proxy=http://127.0.0.1:10808export all_proxy=socks5://127.0.0.1:10808这些只对当前终端会话生效。新开终端后需要重新设置。
取消终端代理
unset http_proxyunset https_proxyunset HTTP_PROXYunset HTTPS_PROXYunset all_proxyunset ALL_PROXY查看当前代理环境变量
env | grep -i proxy或者:
echo "$http_proxy"echo "$https_proxy"echo "$all_proxy"设置不走代理的地址
export no_proxy=localhost,127.0.0.1,::1export NO_PROXY=localhost,127.0.0.1,::1如果要让局域网地址也不走代理:
export no_proxy=localhost,127.0.0.1,::1,192.168.0.0/16,10.0.0.0/8单次命令使用代理
http_proxy=http://127.0.0.1:10808 https_proxy=http://127.0.0.1:10808 curl https://github.com不污染当前终端,适合临时测试。
curl 使用代理
HTTP 代理:
curl -x http://127.0.0.1:10808 https://github.comSOCKS5 代理:
curl -x socks5://127.0.0.1:10808 https://github.com让 DNS 也通过 SOCKS5 代理解析:
curl -x socks5h://127.0.0.1:10808 https://github.com查看连接细节:
curl -v -x http://127.0.0.1:10808 https://github.com只看响应头:
curl -I -x http://127.0.0.1:10808 https://github.comwget 使用代理
单次命令:
wget -e use_proxy=yes -e http_proxy=http://127.0.0.1:10808 -e https_proxy=http://127.0.0.1:10808 https://github.com写入用户配置:
nano ~/.wgetrcuse_proxy = onhttp_proxy = http://127.0.0.1:10808https_proxy = http://127.0.0.1:10808常用参数解释
http_proxy:HTTP 请求使用的代理。
https_proxy:HTTPS 请求使用的代理。
all_proxy:所有协议的通用代理,常用于 SOCKS5。
no_proxy:不走代理的主机或地址。
curl -x:给当前 curl 请求指定代理。
socks5://:使用 SOCKS5 代理,但 DNS 可能仍在本地解析。
socks5h://:使用 SOCKS5 代理,并让代理端解析 DNS。
curl -v:输出详细连接过程。
curl -I:只请求响应头。
wget -e:临时设置 wget 配置项。
终端代理与 curl / wget 配置速查
https://r-gc.github.io/posts/notes/proxy/shell-curl-wget-proxy/