WSL2 网络不可访问

WSL2 网络不可访问

我的 WSL2 无法在任何发行版上连接到互联网。无法访问网络sudo apt-get update。我没有任何 VPN,只有全新的 Windows 11 或 10。它是使用 Wifi 路由器的有线连接,如果我直接从 wifi 使用有线连接,它可以连接到互联网Onu设备设备而不是路由器。类似于下图:

有线连接

现在它来自下面的 Wifi 路由器: 通过路由器有线连接

这是我的ipconfig输出: ipconfig 输出

OS: Windows 11 (Up to date)
Distro: Ubuntu (WSL 2)

我尝试过但失败了的事情:

Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::16). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::19). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (185.125.190.36), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.38), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.39), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.39), connection timed out
Err:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::16). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::19). - connect (101: Network is unreachable)
Err:3 http://archive.ubuntu.com/ubuntu focal-backports InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::16). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::19). - connect (101: Network is unreachable)
Err:4 http://security.ubuntu.com/ubuntu focal-security InRelease
  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2620:2d:4000:1::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2620:2d:4000:1::16). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (185.125.190.39), connection timed out Could not connect to security.ubuntu.com:80 (185.125.190.36), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.38), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.39), connection timed out
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::16). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::19). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (185.125.190.36), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.38), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.39), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.39), connection timed out
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::16). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::19). - connect (101: Network is unreachable)
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::16). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::19). - connect (101: Network is unreachable)
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2620:2d:4000:1::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2620:2d:4000:1::16). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (185.125.190.39), connection timed out Could not connect to security.ubuntu.com:80 (185.125.190.36), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.38), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.39), connection timed out
W: Some index files failed to download. They have been ignored, or old ones used instead.

答案1

我遇到了同样的问题,当我在以太网属性中关闭 ipv6 协议后,问题就解决了。

--编辑-- 请注意,这不是永久/“真正的”解决方案。它似乎仅在您禁用 ipv6 后才有效。

答案2

对于我来说,启用镜像网络模式解决了连接问题:

编辑%UserProfile%\.wslconfig以包括:

[wsl2]
networkingMode=mirrored 

然后使用 重新启动发行版wsl --shutdown。根据https://learn.microsoft.com/en-us/windows/wsl/networking#mirrored-mode-networking这有以下好处:

  • IPv6 支持
  • 使用本地主机地址 127.0.0.1 从 Linux 内部连接到 Windows 服务器
  • 改进了 VPN 的网络兼容性
  • 多播支持
  • 直接从局域网 (LAN) 连接到 WSL

答案3

除非配置损坏,否则 WSL2 会连接到互联网。

虽然实现这一目标最健康的方式可能是阅读WSL2 文档非常小心地、一步一步地去做,我认为我对自己最近的经历的思考可以在经验层面上有所帮助。

正如一些评论所述。WSL 和 WSL2 的网络连接不同,当 WSL 直接作为桥梁工作时,它与 WSL2 Nat 或类似机制一起工作。(向后兼容的一个很好的例子!)

在使用 WSL2 尝试了几次失败后,我遇到了同样的情况,经过研究并再次尝试,我发现如果有必要,我可以设置 WSL 发行版或一般的 WSL 版本。

wsl --set-version <distro name> 2

wsl --set-default-version 2

WSL --> WSL2 版本混淆可能会导致问题。

Hyper V 为 WSL 和 WSL2 添加了一些适配器。我尝试编辑网络适配器,因为添加的 HyperV Bridge Adapter 样式设备影响了我的 IP 寻址系统,我开始在网络上遇到问题,并开始摆弄设置。此时我失去了 WSL2 的互联网输出。当我通过 HyperV 重新创建网络适配器时,问题就解决了。如果您可以检查网络适配器并详细检查它们 - IP 地址、网关等 -

随着时间的推移,如果确实需要,我们可能有机会创建一个可行的示例视频演示。

答案4

无法下载任何 apt 更新/升级。总是超时。

  • WSL2 LTS 22.04.1
  • IP正确
  • DNS 工作

问题出在 WSL2。轻松修复。

在 DOS 命令提示符下

wsl -l -v

获取发行版名称:

wsl --set-version <distro name> 1

需要几分钟才能连接到 v1。

重新启动后一切就都正常工作了。

相关内容