WSL共享Windows代理

WSL 1

WSL 1与主机共享网路,可以直接运行

1
export ALL_PROXY=127.0.0.1:${proxy.port}

其中${proxy.port}是Windows代理客户端的代理端口

必须允许局域网的链接
如图我的代理端口是1082,所以我需要运行

1
export ALL_PROXY=127.0.0.1:1082

WSL 2

WSL 2 使用了hyper-V
先运行

1
cat /etc/resolv.conf

输出这样的结果

1
2
3
4
5
[root@NeoluxOS Administrator]# cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.20.64.1

其中nameserver项就是Windows地址
接下来运行命令

1
export ALL_PROXY=172.20.64.1:1082

可以在.bashrc文件里自动设置
.bashrc文件末尾添加

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