apt-get update
尝试运行并将所需的包安装到我的 WSL 2 Ubuntu 20.04 实例时出现以下错误:
<redacted>:~$ sudo apt-get update && sudo apt-get upgrade
Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu focal-security InRelease
Temporary failure resolving 'security.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
<redacted>:~$ sudo apt install unzip
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
zip
The following NEW packages will be installed:
unzip
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 169 kB of archives.
After this operation, 593 kB of additional disk space will be used.
Err:1 http://archive.ubuntu.com/ubuntu focal/main amd64 unzip amd64 6.0-25ubuntu1
Temporary failure resolving 'archive.ubuntu.com'
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/u/unzip/unzip_6.0-25ubuntu1_amd64.deb Temporary failure resolving 'archive.ubuntu.com'
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
我能做些什么来让它发挥作用?
答案1
问题是由于系统无法联系可以解析域名的 DNS 服务器。以下是一些修复方法...
暂时,您可以/etc/resolv.conf
使用要使用的 DNS 服务器编辑该文件。例如,添加行nameserver 8.8.8.8
,保存文件并重试。
对于持久的 DNS 配置,您可能需要编辑该/etc/systemd/resolved.conf
文件。通过删除符号取消注释DNS
和行。FallbackDNS
#
现在添加您首选的 DNS 服务器。此FallbackDNS
行无论如何都是可选的。
DNS=8.8.8.8
FallbackDNS=8.8.4.4
保存文件并退出。此外,您可能希望清除所有缓存的查询。使用命令systemd-resolve --flush-caches
或resolvectl flush-caches
现在 DNS 应该可以正常工作了。