Windows Subsystem for Linux 2:暂时无法解析“archive.ubuntu.com”

Windows Subsystem for Linux 2:暂时无法解析“archive.ubuntu.com”

我刚刚安装了 Ubuntu 22.04 和 Windows Subsystem for Linux,如下所示本说明

当我运行时sudo apt install update,出现以下错误:

Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Err:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Err:2 http://archive.ubuntu.com/ubuntu jammy InRelease
  Temporary failure resolving 'archive.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.

很久以前(在格式化我的电脑之前),我没有遇到任何问题。

我在网上找不到任何可行的解决方案。我没有 VPN(有些人说这就是问题所在)。

编辑1

我发现这个问题我遵循了 @fossfreedom♦ 的回答。如果我尝试临时解决方案,一切都会正常,直到我重新启动。我使用了:

echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null

但是,如果我尝试永久解决方案,则会收到错误:

$ echo "nameserver 8.8.8.8" | sudo tee /etc/resolvconf/resolv.conf.d/base > /dev/null
tee: /etc/resolvconf/resolv.conf.d/base: No such file or directory

我还没有尝试过那个答案中的“包管理问题”,因为我不认为这是问题所在

编辑2

我检查过的所有 Ubuntu 镜像(西班牙语)都是“最新的”,遵循@NotTheDr01ds 的评论。所以这不是问题。

编辑3:解决方案

由于该问题被标记为重复且已关闭,我无法用自己想出的解决方案来回答我自己的问题,因此我在这里添加了解决方案。

这是该文件的原始内容/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.28.176.1

由于每次启动 WSL 时都会生成此文件,因此更改如下:

echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null

被删除(命令来自此问题)。因此,您必须按照文件中显示的说明进行操作,我使用了此文件中使用的命令问题

sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf

如今,变化已经是永久性的。

我不知道我在做什么或者为什么会遇到这个问题(我是一个基础用户),但如果有人愿意为将来解释这一点,我们欢迎他/她。

相关内容