困惑了我很久的问题今天终于被我解决惹~让我赶紧把它记录下来

确保 Windows 上的代理可用

运行 Clash,打开 Allow LANSystem Proxy

然而我发现 Profiles 里 allow-lan 还是 false,安全起见还是手动给它编辑一下

在终端中试一下有没有代理

1
curl https://www.google.com

在 WSL 中连接主机的代理

将下面函数加入到~/.profile中,记得编辑端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*') #获得网关地址
export proxyPort=1080 #端口
alias proxy='
export https_proxy="http://${hostip}:${proxyPort}";
export http_proxy="http://${hostip}:${proxyPort}";
export all_proxy="http://${hostip}:${proxyPort}";
echo -e "Acquire::http::Proxy \"http://${hostip}:${proxyPort}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
echo -e "Acquire::https::Proxy \"http://${hostip}:${proxyPort}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
'
alias unproxy='
unset https_proxy;
unset http_proxy;
unset all_proxy;
sudo sed -i -e "/Acquire::http::Proxy/d" /etc/apt/apt.conf.d/proxy.conf;
sudo sed -i -e "/Acquire::https::Proxy/d" /etc/apt/apt.conf.d/proxy.conf;
'

测试可用性

1
2
3
source ~/.profile #加载环境
proxy #执行函数 代理生效
curl https://www.google.com #请求Google 网址

如果你一路顺风的话,那么恭喜你已经完成了

但是如果你和我之前一样一直卡住的话,可以尝试关闭 Windows 防火墙

我就是在关了防火墙之后就好了

但是也不能一直关着防火墙是吧,我选择恢复防火墙的默认设置,然后用管理员重新打开 Clash,之后批准权限即可