我想访问在本地网络上的WSL2上运行的NextJs开发服务器。
我将端口3000
添加到防火墙规则中,并使用telnet进行了测试,它不能立即访问。
经过一番研究,我找到了这份文件:https://learn.microsoft.com/en-us/windows/wsl/networking
所以我在我的WSL2示例上运行:
cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.23.16.1
我通过从主机执行ping操作确认了WSL2 IP地址正确:
ping 172.23.16.1
Pinging 172.23.16.1 with 32 bytes of data:
Reply from 172.23.16.1: bytes=32 time<1ms TTL=128
Reply from 172.23.16.1: bytes=32 time<1ms TTL=128
Reply from 172.23.16.1: bytes=32 time<1ms TTL=128
Reply from 172.23.16.1: bytes=32 time<1ms TTL=128
然后使用该IP在Windows 11主机上从提升的提示符下运行以下命令:
netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.23.16.1
现在,我可以远程登录到192.168.0.50:3000
上的Windows主机(这是主机的本地IP),但没有helo,如果我尝试通过Web浏览器访问它,我会得到ERR_EMPTY_RESPONSE
代理端口似乎在那里:
netsh interface portproxy show v4tov4
Listen on ipv4: Connect to ipv4:
Address Port Address Port
--------------- ---------- --------------- ----------
0.0.0.0 3000 172.23.16.1 3000
我试着再添加几个代理端口
Listen on ipv4: Connect to ipv4:
Address Port Address Port
--------------- ---------- --------------- ----------
0.0.0.0 3000 172.23.16.1 3000
192.168.0.50 3000 172.23.16.1 3000
127.0.0.1 3000 172.23.16.1 3000
仍然通过局域网获得ERR_EMPTY_RESPONSE
。我可以通过telnet连接到端口,所以我猜这是与WSL2 Ubuntu 20.04安装有关的东西。
我不知道为什么我不能访问它。在WSL2中没有活动的防火墙
ufw status
Status: inactive
如果我尝试访问主机上的localhost:3000
,它可以工作。如果我尝试访问主机上的http://192.169.0.50:3000/
,我会得到错误,所以一定是某个地方缺少绑定,但我不知道在哪里。
如何调试此问题?
1条答案
按热度按时间e4eetjau1#
文档似乎不正确。
ipconfig
和resolv.conf
似乎显示了错误的IP地址。要获取正确的IP地址,我需要用途:来自powershell的
wsl hostname -I