Windows 10 WSL2 - Ubuntu - apt 更新并解决临时故障

Windows 10 WSL2 - Ubuntu - apt 更新并解决临时故障

我正在运行带有 WSL2 的 Windows 10。我安装了 Ubuntu 20.04 发行版。

当我这样做的时候sudo apt update,它就起作用了

Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Fetched 328 kB in 17s (19.3 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.

然后我尝试添加 podman 的存储库。在/etc/apt/sources.list

deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/ /

但是现在当我执行 sudo apt update 时我得到了

Err:1 https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04  InRelease
  Temporary failure resolving 'download.opensuse.org'
Err:2 http://archive.ubuntu.com/ubuntu focal InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://security.ubuntu.com/ubuntu focal-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Get:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Fetched 214 kB in 34s (6269 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/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: Failed to fetch https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/InRelease  Temporary failure resolving 'download.opensuse.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.

但 ping 仍在进行中

PING download.opensuse.org (195.135.221.134) 56(84) bytes of data.
64 bytes from download.opensuse.org (195.135.221.134): icmp_seq=1 ttl=58 time=36.9 ms
64 bytes from download.opensuse.org (195.135.221.134): icmp_seq=2 ttl=58 time=35.9 ms

删除存储库行后它就可以正常工作了。

这会是什么问题呢?

编辑

我让其他同事也尝试了同样的方法,他们成功了。所以我认为这不是网络上的代理或 DNS 问题。最后一个“罪魁祸首” :-) 似乎是我的笔记本电脑。但为什么呢?

答案1

这对我来说很有效:网上找到的解决方案帮助我解决了家庭网络中的问题,但在办公室使用笔记本电脑时 DNS 解析仍然不起作用。这似乎有效:

在 WSL 中,设置两个发行版,例如“Ubuntu”和“Debian”

  1. 将一个设置为 WSL 版本 1,另一个设置为 WSL 版本 2
  2. wsl --set-version Ubuntu 1
  3. wsl --set-version Debian 2
  4. 将 Ubuntu(WSL 1)中 /etc/resolv.conf 的内容复制到 Debian(WSL 2)

完成只需将 wsl 2 转换回 wsl 1 即可提供更新 /etc/resolv.conf 所需的信息。复制内容,转换回 wsl 2 并将信息传递到 /etc/resolv.conf 中。

事实证明,WSL 1 中的 /etc/resolv.conf 有一个特殊条目“search our-company-domain.de”(以及一些 ipv4 和 ipv6 地址)。其中一个 ip 是我们中央服务器的地址。我想我还必须关闭 resolv.conf 的自动生成。

看:https://gist.github.com/sivinnguyen/8bc0125b274250683a97e149cf270040?permalink_comment_id=3974132#gistcomment-3974132

相关内容