互联网连接问题 wsl 2 ubuntu 22.04(适用于 Linux 的 Windows 子系统)

互联网连接问题 wsl 2 ubuntu 22.04(适用于 Linux 的 Windows 子系统)

最近,我在我的 Windows 10 机器上安装了 WSL 2 Ubuntu 22.04,但似乎什么都不能正常工作,因为我无法访问互联网。我尝试了一些命令,sudo apt update 显示“连接失败”,ping google.com 版本 Windows 10 Enterprise 版本 21H2 安装在 ‎06/‎02/‎2023 操作系统版本 19044.2486 体验 Windows 功能体验包 120.2212.4190.0

~$ sudo apt update
Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Err:1 http://archive.ubuntu.com/ubuntu jammy InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

答案1

我在尝试运行时遇到了这个问题brew update。通过配置/etc/resolv.conf文件解决了这个问题。运行sudo nano /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 127.x.x.x

将其更改为:

# 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 8.8.8.8

现在保存更改CTRL O ENTER CTRL X并测试您的网络是否再次正常工作nslookup askubuntu.com

答案2

在我的笔记本电脑上有一段时间没有使用 WSL2 后,Windows 10 上就出现了这个问题。完全无法访问互联网。

重新启动 wslwsl --shutdown或更改文件/etc/resolv.conf都无法解决问题,安装不同版本的 Ubuntu 并在 wsl 中运行它也无法解决问题。

对我来说,我通过安装Windows 10, version 22H2更新​​并重启笔记本电脑以某种方式解决了这个问题。突然间我又可以上网了。我不确定我之前使用的是哪个版本,但对于任何遇到此问题的人,version 22H2我建议更新到该版本并重启电脑。

相关内容