即使你使用了全局代理,系统中还是有一些软件,不走代理的。需要你单独配置

git设置代理

HTTP 形式

走 HTTP 代理
1
2
git config --global http.proxy "http://127.0.0.1:7890"
git config --global https.proxy "http://127.0.0.1:7890"
走 socks5 代理(如 Shadowsocks)
1
2
git config --global http.proxy "socks5://127.0.0.1:7890"
git config --global https.proxy "socks5://127.0.0.1:7890"
取消设置
1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

SSH 形式

修改 ~/.ssh/config 文件(不存在则新建):

1
2
3
4
5
6
7
8
# 必须是 github.com
Host github.com
HostName github.com
User git
# 走 HTTP 代理
# ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=8080
# 走 socks5 代理(如 Shadowsocks)
# ProxyCommand nc -v -x 127.0.0.1:1080 %h %p

终端走代理

mac端

1
export https_proxy=http://127.0.0.1:8889 http_proxy=http://127.0.0.1:8889 all_proxy=socks5://127.0.0.1:1089
  • 每次打开新的终端都需要重新配置
  • ping 命令不通的原因

Ping走的是 ICMP 协议,代理软件走的是 TCP/IP 协议

可以使用 curl -vv http://www.google.com 来验证

  • 没通
  • image-20200901184053198
  • 通了
  • image-20200901184141428

Windows端

1
set https_proxy=http://127.0.0.1:7890   http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

wsl2

windows 中的clash 需要将 allow lan 打开。

image-20230301110458710

然后再 linux 中新建一个脚本:.proxyrc (文件名可以随意)

1
2
3
#!/bin/bash
host_ip=$(cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " ")
export ALL_PROXY="http://$host_ip:7890"

/etc/resolv.conf 里面可以看到一个ip。不同发行版,这个文件位置不知道一样不一样。

7890 是你 windows 上,代理软件的端口。clash 默认 7890

然后在linux 终端中执行 source .proxyrc

验证是否成功。

image-20230301111401744

参考链接

https://zcdll.github.io/2018/01/27/proxy-on-windows-terminal/

https://zhuanlan.zhihu.com/p/153124468