WSL问题: Temporary failure resolving ‘archive.ubuntu.com‘

今天在WSL进行操作的时候,发现从网络上下载东西无法成功,包括wgetapt-get 等命令都无法正常使用,比如执行sudo apt-get update 的时候会提示

Err:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Err:2 http://archive.ubuntu.com/ubuntu bionic InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

经过查询和搜索(解决bug真的痛苦😫),发现通过一下几行命令可以解决

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

接下来下载东西就都没有问题了。

参考资料: Github上的一个issue

### Ubuntu 系统中无法解析 `archive.ubuntu.com` 的解决方案 当遇到 `Temporary failure resolving 'archive.ubuntu.com'` 错误时,这通常意味着系统的 DNS 配置存在问题。以下是几种可能的解决方案: #### 修改 `/etc/resolv.conf` 一种常见的方法是手动设置 DNS 服务器地址。可以通过删除现有的 `/etc/resolv.conf` 文件并创建一个新的文件来实现这一点。 ```bash sudo rm /etc/resolv.conf sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf' ``` 为了防止该配置被 WSL 自动覆盖,在 WSL 中还需要修改 `/etc/wsl.conf` 文件以禁用自动生成的 DNS 配置。 ```bash sudo bash -c 'echo "[network]" > /etc/wsl.conf' sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf' ``` 最后一步是为了保护 `/etc/resolv.conf` 不再被更改,增加只读属性。 ```bash sudo chattr +i /etc/resolv.conf ``` 这些操作能够有效解决由于 DNS 设置不当引起的问题[^3]。 #### 启用 Systemd-resolved 服务 另一种方式是在 Ubuntu 上启用内置的 DNS 解析服务——Systemd-resolved。此服务可以帮助更好地管理网络连接中的 DNS 请求。 启动并启用 `systemd-resolved.service` 可以改善域名解析性能以及稳定性。 ```bash systemctl enable systemd-resolved.service --now ``` 执行上述命令之后,建议重启计算机使变更生效[^4]。 通过以上两种途径之一应该能成功修复 `Temporary failure resolving 'archive.ubuntu.com'` 这一错误提示信息。
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值