WSL配置可访问Windows本地代理

.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

正常会输出请求响应结构。

相关推荐
AlfredZhao2 天前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80
戴为沐3 天前
Linux内存扩容指南
linux
zylyehuo3 天前
Linux 彻底且安全地删除文件
linux
用户805533698034 天前
主线 U-Boot 上 RK3506:和闭源 rkbin 拔河的三个隐性契约
linux·嵌入式
用户034095297914 天前
linux fcitx 5 雾凇拼音 设置在中文输入法下仍然输入英文标点
linux
Web3探索者6 天前
可视化服务器管理和传统命令行区别是什么?新手教程:Linux 运维到底该用图形界面还是 SSH 命令行?
linux·ssh
zylyehuo6 天前
Linux系统中网线与USB网络共享冲突
linux
Sokach10157 天前
Linux Shell 脚本从零到能用:一个新手的一天学习总结
linux
AlfredZhao7 天前
Docker 容器时区不对,`timedatectl` 不存在怎么办?
linux·timezone
zzzzzz3109 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql