如何让命令使用代理服务器
# 1. 代理类型
* http ------ 远程域名解析 -- 建议
* socks ----
* socks4 ---- 本地域名解析
* socks4a --- 远程域名解析 -- 建议
* socks5 ---- 本地域名解析
* socks5h --- 远程域名解析 -- 建议
# 2. 测试环境
* 本地已存在代理服务器
* http 和 socks 代理都使用: 192.168.68.1:7890
export https_proxy=http://192.168.68.1:7890; # http 代理 -- 建议
curl https://www.google.com -v; # 测试
export https_proxy=socks://192.168.68.1:7890; # socks 代理 -- 使用 socks4
curl https://www.google.com -v; # 测试 -- 域名解析失败
export https_proxy=socks4://192.168.68.1:7890; # socks4 代理
curl https://www.google.com -v; # 测试 -- 域名解析失败
export https_proxy=socks4a://192.168.68.1:7890; # socks4a 代理 -- 建议
curl https://www.google.com -v; # 测试
export https_proxy=socks5://192.168.68.1:7890; # socks5 代理
curl https://www.google.com -v; # 测试 -- 域名解析失败
export https_proxy=socks5h://192.168.68.1:7890; # socks5h 代理 -- 建议
curl https://www.google.com -v; # 测试
curl -x http://192.168.68.1:7890 https://www.google.com -v; # http 代理 -- 建议
curl -x socks://192.168.68.1:7890 https://www.google.com -v; # socks 代理 -- 域名解析失败 -- 使用 socks4
curl -x socks4://192.168.68.1:7890 https://www.google.com -v; # socks4 代理 -- 域名解析失败
curl -x socks4a://192.168.68.1:7890 https://www.google.com -v; # socks4a 代理 -- 建议
curl -x socks5://192.168.68.1:7890 https://www.google.com -v; # socks5 代理 -- 域名解析失败
curl -x socks5h://192.168.68.1:7890 https://www.google.com -v; # socks5h 代理 -- 建议
export https_proxy=http://192.168.68.1:7890; # http 代理 -- 建议
wget https://www.google.com; # 测试
# 1. http 协议
export https_proxy=http://192.168.68.1:7890; # http 代理 -- 建议
git clone https://github.com/liuyunbin/note; # 测试
export https_proxy=socks://192.168.68.1:7890; # socks 代理 -- 域名解析失败
git clone https://github.com/liuyunbin/note; # 测试
export https_proxy=socks4://192.168.68.1:7890; # socks4 代理 -- 域名解析失败
git clone https://github.com/liuyunbin/note; # 测试
export https_proxy=socks4a://192.168.68.1:7890; # socks4a 代理 -- 建议
git clone https://github.com/liuyunbin/note; # 测试
export https_proxy=socks5://192.168.68.1:7890; # socks5 代理 -- 域名解析失败
git clone https://github.com/liuyunbin/note; # 测试
export https_proxy=socks5h://192.168.68.1:7890; # socks5h 代理 -- 建议
git clone https://github.com/liuyunbin/note; # 测试
git config --global http.proxy http://192.168.68.1:7890; # 设置 http 代理 -- 建议
git clone https://github.com/liuyunbin/note; # 测试
git config --global --unset http.proxy; # 取消代理设置
git config --global http.proxy socks://192.168.68.1:7890; # 设置 socks 代理
git clone https://github.com/liuyunbin/note; # 测试 -- 域名解析失败
git config --global --unset http.proxy; # 取消代理设置
git config --global http.proxy socks4://192.168.68.1:7890; # 设置 socks4 代理
git clone https://github.com/liuyunbin/note; # 测试 -- 域名解析失败
git config --global --unset http.proxy; # 取消代理设置
git config --global http.proxy socks4a://192.168.68.1:7890; # 设置 socks4a 代理 -- 建议
git clone https://github.com/liuyunbin/note; # 测试
git config --global --unset http.proxy; # 取消代理设置
git config --global http.proxy socks5://192.168.68.1:7890; # 设置 socks5 代理
git clone https://github.com/liuyunbin/note; # 测试 -- 域名解析失败
git config --global --unset http.proxy; # 取消代理设置
git config --global http.proxy socks5h://192.168.68.1:7890; # 设置 socks5h 代理 -- 建议
git clone https://github.com/liuyunbin/note; # 测试
git config --global --unset http.proxy; # 取消代理设置
# 2. ssh 协议访问
# 2.1 windows 10 --- git-bash
在 ~/.ssh/config 中添加: --- http 代理 -- 建议
Host github.com
ProxyCommand connect -H 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
在 ~/.ssh/config 中添加: --- socks 代理 -- 建议
Host github.com
ProxyCommand connect -S 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
# 2.2 centos 7
在 ~/.ssh/config 中添加: --- http 代理 -- 建议
Host github.com
ProxyCommand nc --proxy-type http --proxy 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
在 ~/.ssh/config 中添加: --- socks4 代理 -- 建议
Host github.com
ProxyCommand nc --proxy-type socks4 --proxy 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
在 ~/.ssh/config 中添加: --- socks5 代理 -- 建议
Host github.com
ProxyCommand nc --proxy-type socks5 --proxy 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
# 2.3 ubuntu 24.04
在 ~/.ssh/config 中添加: --- http 代理 -- 建议
Host github.com
ProxyCommand nc -X connect -x 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
在 ~/.ssh/config 中添加: --- socks4 代理 --- 域名解析失败
Host github.com
ProxyCommand nc -X 4 -x 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
在 ~/.ssh/config 中添加: --- socks5 代理 -- 建议
Host github.com
ProxyCommand nc -X 5 -x 192.168.68.1:7890 %h %p
git clone git@github.com:liuyunbin/note; # 测试
sudo apt clean; # 清空缓存
/etc/apt/apt.conf.d/proxy.conf 内添加: --- http 代理 -- 建议
Acquire::http::Proxy "http://192.168.68.1:7890";
Acquire::https::Proxy "http://192.168.68.1:7890";
sudo apt update; # 测试
sudo apt clean; # 清空缓存
/etc/apt/apt.conf.d/proxy.conf 内添加: --- https + user + passwd 代理 -- 不建议
Acquire::http::Proxy "https://user:passwd@example.com:443";
Acquire::https::Proxy "https://user:passwd@example.com:443";
sudo apt update; # 测试
sudo apt clean; # 清空缓存
/etc/apt/apt.conf.d/proxy.conf 内添加: --- socks 代理 --- 不支持
Acquire::http::Proxy "socks://192.168.68.1:7890";
Acquire::https::Proxy "socks://192.168.68.1:7890";
sudo apt update; # 测试
sudo apt clean; # 清空缓存
/etc/apt/apt.conf.d/proxy.conf 内添加: --- socks4 代理 --- 不支持
Acquire::http::Proxy "socks4://192.168.68.1:7890";
Acquire::https::Proxy "socks4://192.168.68.1:7890";
sudo apt update; # 测试
sudo apt clean; # 清空缓存
/etc/apt/apt.conf.d/proxy.conf 内添加: --- socks4a 代理 --- 不支持
Acquire::http::Proxy "socks4a://192.168.68.1:7890";
Acquire::https::Proxy "socks4a://192.168.68.1:7890";
sudo apt update; # 测试
sudo apt clean; # 清空缓存
/etc/apt/apt.conf.d/proxy.conf 内添加: --- socks5 代理 --- 不支持
Acquire::http::Proxy "socks5://192.168.68.1:7890";
Acquire::https::Proxy "socks5://192.168.68.1:7890";
sudo apt update; # 测试
sudo apt clean; # 清空缓存
/etc/apt/apt.conf.d/proxy.conf 内添加: --- socks5h 代理 -- 建议
Acquire::http::Proxy "socks5h://192.168.68.1:7890";
Acquire::https::Proxy "socks5h://192.168.68.1:7890";
sudo apt update; # 测试
sudo apt clean; # 清空缓存
sudo apt update -o Acquire::http::Proxy="socks5h://192.168.68.1:7890"; # 测试 -- 临时使用 -- 建议