apt-get 不工作,我该如何重置 /etc/apt/sources

apt-get 不工作,我该如何重置 /etc/apt/sources

由于某种原因,我无法安装新的应用程序,也无法在 ubuntu 14 服务器上运行 apt-get update

当我运行 apt-get update 时,我得到以下信息:

apt-get update
Err http://gb.archive.ubuntu.com trusty InRelease

Err http://security.ubuntu.com trusty-security InRelease

Err http://gb.archive.ubuntu.com trusty-updates InRelease

Err http://gb.archive.ubuntu.com trusty-backports InRelease

Err http://security.ubuntu.com trusty-security Release.gpg
  Could not resolve 'security.ubuntu.com'
Err http://gb.archive.ubuntu.com trusty Release.gpg
  Could not resolve 'gb.archive.ubuntu.com'
Err http://gb.archive.ubuntu.com trusty-updates Release.gpg
  Could not resolve 'gb.archive.ubuntu.com'
Err http://gb.archive.ubuntu.com trusty-backports Release.gpg
  Could not resolve 'gb.archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/trusty/InRelease

W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease

W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/trusty-backports/InRelease

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/trusty-security/InRelease

W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg  Could not resolve 'gb.archive.ubuntu.com'

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg  Could not resolve 'security.ubuntu.com'

W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg  Could not resolve 'gb.archive.ubuntu.com'

W: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/dists/trusty-backports/Release.gpg  Could not resolve 'gb.archive.ubuntu.com'

W: Some index files failed to download. They have been ignored, or old ones used instead.

我有网络连接,可以 ping 各种 IP。有没有安全的方法来重置出厂默认设置(虽然我没有修改列表)/etc/apt/source 列表?

谢谢,约翰

答案1

  1. 确保名称服务器 IP 在/etc/resolv.conf文件正在从您的机器 ping 出去。
  2. 如果没有,请尝试使用可靠的名称服务器,如 Google 的 8.8.8.8 和 8.8.4.4。
  3. 尝试将 resolv.conf 中找到的名称服务器 IP 放入您的/etc/网络/接口文件nameserver <IP of the DNS server>并通过运行重新启动网络/etc/init.d/networking restart,看看是否有效。
  4. 如果都不起作用,请尝试更改顺序/etc/nsswitch.conf,行 host: 将 dns 放在第一位。hosts: files dns mdns4_minimal [NOTFOUND=return] mdns4

您可以找到有关类似问题的讨论这里

答案2

如果您有防火墙(例如 UFW),则可以添加例外或暂时禁用防火墙。有时防火墙会阻止传出请求,因此无论您对名称服务器配置进行什么更改,除非防火墙允许传出流量或禁用防火墙,否则它都不会起作用。

相关内容