刚刚买了一个运行 Ubuntu 11.04 的新 VPS,并尝试更新它。我遇到了这个错误。每次使用 apt-get 时都会遇到同样的错误
login as: root
[email protected]'s password:
Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-8-generic-pae i686)
* Documentation: https://help.ubuntu.com/
Last login: Mon May 7 19:55:45 2012 from 108.192.44.54
root@Rx:~# apt-get update
Err http://security.ubuntu.com natty-security InRelease
Err http://archive.ubuntu.com natty InRelease
Err http://security.ubuntu.com natty-security Release.gpg
Temporary failure resolving 'security.ubuntu.com'
Err http://archive.ubuntu.com natty-updates InRelease
Err http://archive.ubuntu.com natty Release.gpg
Temporary failure resolving 'archive.ubuntu.com'
Err http://archive.ubuntu.com natty-updates Release.gpg
Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/natty/InRelease
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/natty-updates/InRelease
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/natty-security/InRelease
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/natty-security/Release.gpg Temporary failure resolving 'security.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/natty/Release.gpg Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/natty-updates/Release.gpg Temporary failure resolving 'archive.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
root@Rx:~#
如果需要的话,这是我的 /etc/apt/sources.list
root@Rx:/etc# more /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu natty main
deb http://archive.ubuntu.com/ubuntu natty-updates main
deb http://security.ubuntu.com/ubuntu natty-security main
deb http://archive.ubuntu.com/ubuntu natty universe
deb http://archive.ubuntu.com/ubuntu natty-updates universe
如果需要的话,我会做一个 ping 测试:
root@Rx:~# ping -n 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=56 time=13.3 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=56 time=13.2 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=56 time=13.4 ms
64 bytes from 8.8.8.8: icmp_req=4 ttl=56 time=13.3 ms
^C
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 13.243/13.326/13.428/0.066 ms
root@Rx:~#
这是 /etc/resolv.conf
root@Rx:~# more /etc/resolv.conf
nameserver 199.193.248.1
答案1
问题在于您原来的 DNS 服务器没有响应您的查询。您可以将另一个服务器添加到列表中进行检查。8.8.8.8(由 Google 提供)是最容易记住的。
将该行添加nameserver 8.8.8.8
到您的 /etc/resolv.conf 以查询该服务器。
如果原始服务器是 VPS 提供商提供给您的,您可能需要向他们的支持团队提出这个问题 - 可能有某种管理工具依赖于它。除此之外,您可以永远使用 8.8.8.8 作为您的主 DNS。
答案2
似乎 DNS 解析不起作用。您可以执行以下操作:
ping 199.193.248.1
nslookup any_site_name 199.193.248.1
PS 在 Ubuntu 18.04 中,/etc/resolv.conf 文件由 systemd-resolved 管理,不得编辑。您必须在此处将正确的名称服务器(例如 (8.8.8.8))添加到 /etc/netplan/*.yaml:
nameservers:
addresses: [..., 8.8.8.8]
手动或通过此一行代码,如果字符串“addresses:”在文件中只有一个
sed -r 's/(addresses: \[.*)\]/\1, 8.8.8.8\]/g' /etc/netplan/01-netcfg.yaml |
sudo tee /etc/netplan/01-netcfg.yaml &&
sudo netplan apply
(这是 ubuntu 服务器和一个文件 01-netcfg.yaml)
当然,如果你在组织中工作,你不能使用8.8.8.8,请使用你自己的DNS服务器。
答案3
官方评论/etc/resolv.conf明确指出该文件不应编辑。在较新的 Ubuntu 服务器中,您应该将文件签入/etc/netplan. 检查其中的网络网关配置,特别是如果您不使用 dhcp。