通过本地网络连接到 WSL2 服务器 [英] Connecting to WSL2 server via local network

查看:178
本文介绍了通过本地网络连接到 WSL2 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的 Windows 10 机器上使用 WSL2/Ubuntu 开发一个 rails 应用程序,这很棒!问题是我无法从同一网络中的另一台计算机连接到我的服务器.

I'm developing a rails app using WSL2/Ubuntu on my Windows 10 machine, which is great! The problem is I can't connect to my server from another computer in the same network.

为了更清楚,我在 localhost:3000 上运行 Puma 服务器

For further clarity, I am running a Puma server on localhost:3000

我尝试了以下方法:

  1. 直接连接到分配给以太网适配器 vEthernet (WSL) 的 IP 地址 -> 172.26.208.1:3000
  2. 直接连接到主机的 IPv4 地址 -> 192.168.0.115
  3. 添加防火墙例外(使用 Bitdefender)
  4. 绑定上面的IP rails s -b 172.26.208.1 -p 3000

到目前为止,以上都没有奏效......我想做的是:

None of the above have worked thus far... What I'd like to do is:

  • 在另一台笔记本电脑/平板电脑/手机上测试网站
  • 在另一台计算机上使用 VScode

我是否遗漏了至少可以正确查看网站的内容?(对 VScode 部分的任何评论将不胜感激)

Is there anything I'm missing to at least see the website correctly? (and any comments on the VScode part would be appreciated)

推荐答案

看到这个视频,对我有帮助:

See this video, it helped me:

https://www.youtube.com/watch?v=yCK3esuYm4

netsh interface portproxy add v4tov4 listenport=<port-to-listen> listenaddress=0.0.0.0 connectport=<port-to-forward> connectaddress=<forward-to-this-IP-address>

例如

netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.30.16.3

Microsoft 已在其 WSL1 到 WSL2 比较页面

Microsoft has published a little bit of information about this on their WSL1 to WSL2 comparison page

不要忘记在后面提供反馈.

Don't forget to put feedback after.

这篇关于通过本地网络连接到 WSL2 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆