apt-get update无法获取文件,“临时故障解决…”错误

Err http://archive.canonical.com natty InRelease Err http://security.ubuntu.com oneiric-security InRelease Err http://extras.ubuntu.com natty InRelease Err http://security.ubuntu.com oneiric-security Release.gpg Temporary failure resolving 'security.ubuntu.com' Err http://archive.canonical.com natty Release.gpg Temporary failure resolving 'archive.canonical.com' Err http://extras.ubuntu.com natty Release.gpg Temporary failure resolving 'extras.ubuntu.com' Err http://gb.archive.ubuntu.com oneiric InRelease Err http://gb.archive.ubuntu.com oneiric-updates InRelease Err http://gb.archive.ubuntu.com natty-backports InRelease Err http://gb.archive.ubuntu.com oneiric Release.gpg Temporary failure resolving 'gb.archive.ubuntu.com' Err http://gb.archive.ubuntu.com oneiric-updates Release.gpg Temporary failure resolving 'gb.archive.ubuntu.com' Err http://gb.archive.ubuntu.com natty-backports Release.gpg Temporary failure resolving 'gb.archive.ubuntu.com' Reading package lists... Done W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/oneiric/InRelease W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/oneiric-updates/InRelease W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/natty-backports/InRelease W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/oneiric-security/InRelease W: Failed to fetch http://archive.canonical.com/ubuntu/dists/natty/InRelease W: Failed to fetch http://extras.ubuntu.com/ubuntu/dists/natty/InRelease W: Failed to fetch http://archive.canonical.com/ubuntu/dists/natty/Release.gpg Temporary failure resolving 'archive.canonical.com' W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/oneiric-security/Release.gpg Temporary failure resolving 'security.ubuntu.com' W: Failed to fetch http://extras.ubuntu.com/ubuntu/dists/natty/Release.gpg Temporary failure resolving 'extras.ubuntu.com' W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/oneiric/Release.gpg Temporary failure resolving 'gb.archive.ubuntu.com' W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/oneiric-updates/Release.gpg Temporary failure resolving 'gb.archive.ubuntu.com' W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/natty-backports/Release.gpg Temporary failure resolving 'gb.archive.ubuntu.com' W: Some index files failed to download. They have been ignored, or old ones used instead. 

当我尝试运行sudo apt-get update时,这就是我所看到的。 我昨天对我的实例做了更新,现在正在经历这个。

概观

您的问题分为两部分:

  • 修复临时解决消息
  • 修复包管理问题

暂时的决心

这个问题很可能是:

  • 由于您的Internet服务提供商未正确将Internet命名(DNS)转发到其或外部DNS服务器,或者
  • 由于您的网络更改同样阻止了此命名 – 例如,新路由器/调制解调器,使用新配置重新配置交换机。

让我们看看可能的DNS解决问题。

首先,临时将已知的DNS服务器添加到您的系统。

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

然后运行sudo apt-get update

如果这样可以修复您的临时解析消息,那么请等待24小时,看看您的ISP是否为您解决了问题(或者只是联系您的ISP) – 或者您可以永久地将DNS服务器添加到您的系统中:

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

8.8.8.8是谷歌自己的DNS服务器。

资源

您可以使用的另一个示例DNS服务器是OpenDNS – 例如:

 echo "nameserver 208.67.222.222" | sudo tee /etc/resolvconf/resolv.conf.d/base > /dev/null 

包管理问题

除了临时解决问题 – 你还有一些需要纠正的软件包管理问题 – 我假设你最近尝试过从一个Ubuntu版本升级到下一个推荐版本 – 在你的情况下从Natty(11.04)到Oneiric(11.10)

打开终端并输入

 sudo nano /etc/apt/sources.list 

查找列表中具有与您期望的不同的分发名称的行 – 在您的情况下 – 您已升级到oneiric但是您有另一个版本名称natty

例如,查找看起来像deb http:/archive.canonical.com/ natty backports

例如,在行的开头添加#以将其注释掉

#deb http:/archive.canonical.com/ natty backports

保存并重新运行:

 sudo apt-get update && sudo apt-get upgrade 

您不应该有任何更多的发布命名错误。

在撰写本文时,可能的常见发布名称包括lucidmaverickquantalquantalprecisequantalquantalsaucytrustyutopicvivid

请注意,这个答案是针对旧版本的Ubuntu编写的。 当前版本使用由D-Bus控制的本地名称服务器,此答案的诊断部分适用于此,但不适用于解决方案。 如果/etc/resolv.conf包含nameserver 127.0.1.1或更多nameserver 127.XYZ ,请不要修改它。

“临时故障解决…”表示您的DNS (即从主机名到IP地址的转换)不起作用。 你最近在机器上重新配置了什么吗? 如果不是,这可能是您的ISP的暂时性错误。

ping -n 8.8.8.8是否显示64 bytes from 8.8.8.8: …64 bytes from 8.8.8.8: … ? (按Ctrl + C停止ping 。)

  • 如果没有,则具体存在IP连接问题。 运行traceroute -n 8.8.8.8并查看它停止的位置:如果它位于您的家中/办公室,请检查您的网络设备。 如果您可以联系您的ISP,请向他们投诉。
  • 如果是这样,您特别遇到DNS问题。 检查/etc/resolv.conf的内容; 应该有一个像nameserver 1.2.3.4这样的行(可能不止一个)。 如果存在这些行,那么您的ISP中可能存在一个短暂的问题,并且您可以通过向该文件添加nameserver 8.8.8.8来解决它(这声明了一个额外的DNS服务器,由Google免费提供) )。 如果nameserver之后的第一个数字是127,那么您的计算机上有一个DNS中继(这是一件好事),您必须配置该DNS中继而不是修改/etc/resolv.conf 。 在现代版本的Ubuntu上,默认情况下有一个DNS中继,它是Dnsmasq ,它由D-Bus控制。

您可以在dir / etc / apt /上找到的文件sources.list中注释未解析的repo

修改sources.list后,清除apt-get repo as

 apt-get clean 

然后更新

 apt-get update 

错误将消失

有时,当您在代理服务器后面时,甚至有必要在/etc/apt/生成apt.conf文件并用特定条目填充它,例如:

 Acquire::http::proxy "http://:"; Acquire::https::proxy "http://:"; Acquire::ftp::proxy "http://:"; 

如果需要validation,配置文件如下所示:

 Acquire::http::proxy "http://:@:"; Acquire::https::proxy "http://:@:"; Acquire::ftp::proxy "http://:@:"; 

运行apt-get命令时遇到了类似的错误。 事实certificate我在控制台上打开了软件更新面板。
这似乎阻止了命令行apt-get ,但我不确定。

这是一个DNS问题。 检查/etc/resolv.conf文件。

例如,在我的情况下,当我遇到此问题并检查此文件时,文件为空! 但它应该包含你的dns-nameserver

矿:

 nameserver 192.168.10.x 

192.168.10.x is my gateway ip address

我有这个错误。 根据Linode支持的提示,我注释掉了/ etc / hosts中的所有IPv6行,然后apt-get update开始工作。

对于使用EC2的用户,请记住检查您的安全组设置是否允许与要更新的网站的出站连接。 您可以设置所有流量出站设置,看看它是否有效。

接受的解决方案对我不起作用。 首先,只有apt-get update警告我Temporary failure resolving 'foo.com' ,但是当我尝试使用nslookup foo.comping foo.com ,它运行正常!

我解决这个bug的难以理解的黑客/修复方法是使用这个简短的脚本手动将已解析的域添加到/etc/hosts

 resolveAptHosts() { mapfile -t hosts < <( sed -n -r '/^#/d; s;deb(-src)? (http://|ftp://)?([^/ ]+).*;\3;p'\ /etc/apt/sources.list | sort | uniq ) # delete all hosts from /etc/hosts, eg, from an earlier call sudo sed -i -r '/^[0-9]{1,3}(\.[0-9]{1,3}){3}[ \t]+('"$( printf '|%s'\ "${hosts[@]//./\\.}" | sed 's/^|//' )"')[ \t]*$/d' /etc/hosts for host in ${hosts[@]}; do ip=$( nslookup "$host" | sed -n -r 's|Address:[ \t]*([0-9.]+).*|\1|p' | tail -1 ) sudo bash -c "echo $ip $host >> /etc/hosts" done } 

现在更新应该工作:

 resolveAptHosts && sudo apt-get update 

如果有人知道为什么这个解决方法有效以及如何解决这个真正的错误,我将永远感恩。 我也尝试使用sudo apt-get update -o Acquire::ForceIPv4=true来排除IPv6解决问题,但这也没有帮助。