-
-
Save libChan/3a804a46b532cc326a2ee55b27e8ac19 to your computer and use it in GitHub Desktop.
| # WSL通过Win访问网络,所以WSL的网关指向的是Windows,DNS服务器指向的也是Windows,设置WSL的proxy为win的代理ip+端口即可 | |
| # WSL中的DNS server在/etc/resolv.conf中查看,该文件是由/etc/wsl.conf自动生成的。 | |
| # 如果关闭了wsl.conf中自动生成resolve.conf并自行修改了resolve.conf,DNS nameserver并不是本机win ip | |
| # 需要开启wsl.conf的自动生成,再运行以下命令 | |
| # https://zhuanlan.zhihu.com/p/153124468 | |
| # 添加到环境变量设置中,例如~/.zshrc | |
| export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*') | |
| export https_proxy="http://${hostip}:7890" | |
| export http_proxy="http://${hostip}:7890" |
我访问google是可以通了,但是TLS握手失败: try: context = ssl.create_default_context() with socket.create_connection((host, port), timeout=5) as sock: with context.wrap_socket(sock, server_hostname=host) as ssock: print(f"✅ TLS 握手成功: {ssock.version()}") except Exception as e: print("❌ TLS 握手失败:", e)
以下代码失败了,有朋友遇到了吗?遇到相同问题,可以访问google, 比如 curl -v google.com, 但是比如 docker pull 就会 TLS handshake timeout(任何镜像仓库)
我的问题解决了,是Clash 的 TUN 模式的问题,改用普通的系统代理关闭 TUN 模式然后再设置 http proxy 就可以了。
- window 防火墙 7890 端口放开。 cmd 命令行执行:
netsh advfirewall firewall add rule name="Open Port 7890" dir=in action=allow protocol=TCP localport=7890- clash 设置 allow lan
- wsl 更改 ~/.bash_profile
export hostip="192.168.31.151" #改成你自己的局域网IP地址 export https_proxy="http://$/{hostip}:7890" export http_proxy="http://$/{hostip}:7890" export all_proxy="socks5://${hostip}:7890"
source ~/.bash_profile- 使用
wget google.com测试
https_proxy、http_proxy多了一个/斜杠啊
环境: Windows 19045 + WSL 2 Ubuntu
问题: WSL 中 ping 172.25.x.x(从 /etc/resolv.conf 的 nameserver 获取,是 Windows 在 WSL NAT 中的虚拟 IP)能通,但 curl/telnet 连接失败。
原因 & 解决: WSL 2 的 NAT 模式只支持 ICMP,TCP 连接需要用 Windows 实际 IP。在 PowerShell 运行 ipconfig 找到以太网/WiFi 的 IPv4 地址(如 192.168.x.x),然后在 WSL 中运行 export http_proxy=http://192.168.x.x:7890 即可访问代理。
export https_proxy="http://127.0.0.1:7890"
export http_proxy="http://127.0.0.1:7890"
export all_proxy="socks5://127.0.0.1:7890"
Work for me