在.bashrc文件加入:
bash
WIN_HOST=$(ip route | awk '/default/ {print $3}')
unset http_proxy
unset https_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
PROXY_PORT=17891 # Windows本地代理端口
if timeout 0.5 bash -c "echo > /dev/tcp/$WIN_HOST/$PROXY_PORT" 2>/dev/null; then
export http_proxy="http://$WIN_HOST:$PROXY_PORT"
export https_proxy="http://$WIN_HOST:$PROXY_PORT"
echo "[WSL-NET-FIX] Proxy detected: $WIN_HOST:$PROXY_PORT"
else
echo "[WSL-NET-FIX] No proxy detected, using direct network"
fi
然后编辑/etc/resolv.conf加入DNS解析地址
bash
nameserver 1.1.1.1
nameserver 8.8.8.8
测试
bash
curl -I https://google.com
curl -I https://baidu.com
正常会输出请求响应结构。