方案#
不同的代理软件操作可能有所不同,但不多解释了... 这里以Clash为例。
如图所示,代理服务端口号为 “7890”,一定要记得打开ALLOW LAN。
打开 wsl 的 bash 文件,以 .bashrc
文件为例:
添加以下内容
# 代理列表
# 注意,如果不导出(export),其他bash脚本将无法访问这个变量,为了能在 .ssh/config 中访问到,必须导出一下
# https://unix.stackexchange.com/a/495163
export host_ip=$(cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " ")
# wget比较特殊,不认all_proxy,只认http_proxy和https_proxy
alias proxy="export all_proxy=http://$host_ip:7890 http_proxy=http://$host_ip:7890 https_proxy=http://$host_ip:7890"
alias unproxy='unset all_proxy http_proxy https_proxy'
proxy
此时再次查看代理软件,如图所示,代理 wsl 成功!