You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSL2无法访问Windows端口转发地址求助

解决WSL2访问Windows绑定127.128.0.11端口的问题

问题原因

你当前的netsh portproxy命令监听的是Windows的127.0.0.1回环地址,但WSL2的localhost指向自身的回环栈,无法直接映射到Windows的回环地址。而服务绑定127.0.0.1时WSL2能访问,是因为WSL默认对Windows的127.0.0.1做了特殊转发,但这个规则不覆盖其他回环段地址(如127.128.0.11)。

可行解决方案

方案1:调整portproxy监听Windows局域网IP

  1. 获取Windows的WSL网卡IP:在Windows命令行执行ipconfig,找到Ethernet adapter vEthernet (WSL)项下的IPv4地址(示例:192.168.1.100)。
  2. 删除原有无效转发规则:
    netsh interface portproxy delete v4tov4 listenaddress=127.0.0.1 listenport=11224
    
  3. 添加新的转发规则,监听Windows局域网IP:
    netsh interface portproxy add v4tov4 listenaddress=192.168.1.100 listenport=11224 connectaddress=127.128.0.11 connectport=11224
    
  4. 在WSL2中直接访问该IP加端口:
    wget 192.168.1.100:11224
    

方案2:修改Python服务绑定地址

若权限允许,直接让服务绑定到0.0.0.0或Windows局域网IP,跳过转发步骤:

# 绑定所有可用地址
python3.exe -m http.server -b 0.0.0.0 11224
# 或绑定指定局域网IP
python3.exe -m http.server -b 192.168.1.100 11224

之后在WSL2中用Windows局域网IP访问即可。

方案3:配置WSL2 hosts简化访问(可选)

若不想每次输入IP,在WSL2中修改/etc/hosts添加映射:

sudo echo "192.168.1.100 windows-host" >> /etc/hosts

之后可直接用wget windows-host:11224访问。

额外排查点

若上述方案无效,检查公司笔记本的防火墙规则,确认是否允许WSL网卡的流量访问该端口。同时避免使用${HOST}.local,该地址依赖mDNS解析,可能在企业网络中被限制。

内容的提问来源于stack exchange,提问作者mordnis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 01:53:14