适用于 Linux 2 的 Windows 子系统:解决“archive.ubuntu.com”时出现临时故障

Abe*_*rez 15 apt windows-subsystem-for-linux 22.04

我刚刚按照此说明安装了带有适用于 Linux 的 Windows 子系统的 Ubuntu 22.04 。

\n

当我运行时sudo apt install update,我收到以下错误:

\n
Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease\nIgn:2 http://archive.ubuntu.com/ubuntu jammy InRelease\nIgn:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease\nIgn:1 http://security.ubuntu.com/ubuntu jammy-security InRelease\nIgn:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease\nIgn:1 http://security.ubuntu.com/ubuntu jammy-security InRelease\nIgn:2 http://archive.ubuntu.com/ubuntu jammy InRelease\nErr:1 http://security.ubuntu.com/ubuntu jammy-security InRelease\n  Temporary failure resolving \'security.ubuntu.com\'\nIgn:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease\nIgn:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease\nIgn:2 http://archive.ubuntu.com/ubuntu jammy InRelease\nIgn:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease\nIgn:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease\nErr:2 http://archive.ubuntu.com/ubuntu jammy InRelease\n  Temporary failure resolving \'archive.ubuntu.com\'\nErr:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease\n  Temporary failure resolving \'archive.ubuntu.com\'\nErr:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease\n  Temporary failure resolving \'archive.ubuntu.com\'\nReading package lists... Done\nBuilding dependency tree... Done\nReading state information... Done\nAll packages are up to date.\nW: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease  Temporary failure resolving \'archive.ubuntu.com\'\nW: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease  Temporary failure resolving \'archive.ubuntu.com\'\nW: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease  Temporary failure resolving \'archive.ubuntu.com\'\nW: Failed to fetch http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease  Temporary failure resolving \'security.ubuntu.com\'\nW: Some index files failed to download. They have been ignored, or old ones used instead.\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

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

\n

编辑1

\n

我发现了这个问题,并遵循了@fossfreedom\xe2\x99\xa6 的答案。如果我尝试临时解决方案,一切正常,直到我重新启动。我用了:

\n
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n
$ echo "nameserver 8.8.8.8" | sudo tee /etc/resolvconf/resolv.conf.d/base > /dev/null\ntee: /etc/resolvconf/resolv.conf.d/base: No such file or directory\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

编辑2

\n

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

\n

编辑3:解决方案

\n

由于问题被标记为重复和关闭,我无法用我找到的解决方案回答我自己的问题,所以我在此处添加解决方案。

\n

这是文件的原始内容/etc/resolv.conf

\n
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:\n# [network]\n# generateResolvConf = false\nnameserver 172.28.176.1\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n
sudo rm /etc/resolv.conf\nsudo bash -c \'echo "nameserver 8.8.8.8" > /etc/resolv.conf\'\nsudo bash -c \'echo "[network]" > /etc/wsl.conf\'\nsudo bash -c \'echo "generateResolvConf = false" >> /etc/wsl.conf\'\nsudo chattr +i /etc/resolv.conf\n
Run Code Online (Sandbox Code Playgroud)\n

现在,变化是永久性的。

\n

我不知道我在做什么或为什么会遇到这个问题(我是基本用户),但如果有人想为将来解释它,欢迎他/她。

\n