目的:在windows上运行代理软件,让wsl也能够访问外网链接。
- 允许局域网连接
宿主机(win10)的代理软件clash要打开 “允许局域网连接” 这个选项
- 配置防火墙
控制面板->系统和安全->Windows Defender 防火墙->允许应用通过 Windows 防火墙中,把你的代理软件的相关项全部打上勾。
- 配置wsl环境 编辑 ~/.bashrc,如果使用的是clash,在文件末尾添加下面的代码。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# add proxy
export hostip=$(ip route | grep default | awk '{print $3}')
export socks_hostport=7890
export http_hostport=7890
alias proxy='
export https_proxy="http://${hostip}:${http_hostport}"
export http_proxy="http://${hostip}:${http_hostport}"
export ALL_PROXY="socks5://${hostip}:${socks_hostport}"
export all_proxy="socks5://${hostip}:${socks_hostport}"
'
alias unproxy='
unset ALL_PROXY
unset https_proxy
unset http_proxy
unset all_proxy
'
alias echoproxy='
echo $ALL_PROXY
echo $all_proxy
echo $https_proxy
echo $http_proxy
'
#end proxy
source ~/.bashrc
- 最终的效果是,每次在需要开启代理的终端中输入proxy即可开启代理;输入unproxy可以关闭代理: