WSL2 默认使用 NAT 网络,因此 DNS 服务器执行 Windows,在 /etc/resolv.conf 中可以找到 DNS 服务器。
之后打开 Windows Calsh 的局域网连接,并找到端口。

server=`awk '$1 == "nameserver" {print $2}' /etc/resolv.conf`
port=7897
export http_proxy="http://$server:$port"
export https_proxy="http://$server:$port"
source proxy.sh 执行上述脚本即可。
https://learn.microsoft.com/en-us/windows/wsl/networking#default-networking-mode-nat
1