无法从 wsl2 访问绑定在 0.0.0.0 上的服务

Cannot access service bound on 0.0.0.0 from wsl2

我有一个 ssh 隧道,是我在 MobaXterm 的帮助下完成的,看起来像这样

local pc     <= remote server
0.0.0.0:8545 <= 127.0.0.1:8545

所以我做了一些测试,我可以在本地电脑上使用 http://127.0.0.1:8545 的 curl 访问远程服务器上的服务。我在 git bash 和 cmd 上尝试了 curl,两者都有效,但 wsl2 上的 curl 声称连接已被拒绝。

命令:

>curl -H "Content-Type: application/json" -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_blockNumber\",\"params\":[],\"id\":83}" http://127.0.0.1:8545
{"jsonrpc":"2.0","id":83,"result":"0x6c360c"}

git bash:

$ curl -XPOST -H "Content-type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}' 'http://127.0.0.1:8545'
{"jsonrpc":"2.0","id":83,"result":"0x6c35b8"}

wsl2:

$ curl -XPOST -H "Content-type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}' 'http://127.0.0.1:8545'
curl: (7) Failed to connect to 127.0.0.1 port 8545: Connection refused

我也试过在127.0.0.1:8545和172.27.96.1:8545绑定隧道。由于那些不起作用,我想先尝试让 0.0.0.0:8545 起作用,然后再尝试更具体的东西。

如何从 wsl2 访问该服务?

我通过从 wsl 和 windows (cmd) 绑定到 http://172.20.144.1:8545 (the gateway address of wsl network). I could then reach the service at http://172.20.144.1:8545 使其工作。

唯一的问题是 wsl 网络的网关 IP 在每次重启时都会改变。

我还不确定 windows 是否为 wsl 的网络网关提供地址解析。