Ubuntu服务器的apt-get说“(-5 – 没有地址与主机名相关)”

我有一个Ubuntu 12.04服务器。 运行sudo apt-get update会产生这样的错误:

W: Failed to fetch http://au.archive.ubuntu.com/ubuntu/dists/precise-backports/main/binary-i386/Packages Something wicked happened resolving 'au.archive.ubuntu.com:http' (-5 - No address associated with hostname) 

我可以ping通networking上的所有其他主机,也可以ping通Google的DNS 8.8.8.8。 但是我无法ping通www.google.com。

所以,我猜测我的DNS设置有问题,但不知道是什么。

我使用静态IP和我的/ etc / network /接口看起来像这样:

  auto eth0 iface eth0 inet static address 192.168.1.50 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.0.255 gateway 192.168.1.1 #dns-nameserver 203.12.160.35 203.12.160.36 #nameserver 203.12.160.35 203.12.160.36 

我的/etc/resolv.conf和/etc/resolvconf/resolv.conf.d/base都是空的,我的/etc/resolvconf/resolv.conf.d/original说:

  nameserver 192.168.1.1 

任何帮助将不胜感激。

PS我GOOGLE了一下,常见的解决办法是切换到DHCP,我不想做,因为这是我的家庭服务器。

感谢Srini

将自己的(或公共)名称服务器地址添加到/etc/resolvconf/resolv.conf.d/base然后运行resolvconf -u以更新configuration。

你networkingconfiguration中的两个地址203.12.160.35203.12.160.36是你应该使用的名称服务器吗? 在这种情况下,将这些添加到base文件。

编辑/etc/resolv.conf; 加:

 nameserver 208.67.222.222 

(这将使用opendns)

重启networking: /etc/init.d/networking restart

Ubuntu 12.04中的DNS操作已经发生了很大的变化,在我看来有点不完善,但是这是一个改进,它只是缺less本地的dnscaching,可以手动安装。

http://www.stgraber.org/2012/02/24/dns-in-ubuntu-12-04/

如何正确添加静态条目到resolv.conf是打开你的terminal。

 sudo nano /etc/resolvconf/resolv.conf.d/base 

添加两个公共和你的本地,如果你有一个

 nameserver [your_local] nameserver 208.67.222.222 nameserver 208.67.220.220 
  • 备份你现有的resolv.conf

    cp /etc/resolv.conf ~/resolv.conf_backup

现在确保/etc/resolv.conf是/run/resolvconf/resolv.conf的符号链接

 sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf 

重新configurationresolvconf软件包

 sudo dpkg-reconfigure resolvconf 

当被问及“为dynamic更新准备/etc/resolv.conf?” select“是”并按照说明操作。

故障排除

您可能会遇到默认超时会妨碍性能的情况(名称parsing的延迟时间可能相当长,特别是数据库/ http服务)

有三种方法可以解决此问题:

  • 将名称条目添加到您的主机文件,这是一个更多的工作,而不是一个修复

    编辑/ etc / hosts并为主机添加静态条目。 请注意这可能会延迟debugging

  • 修改resolvconf包中的默认超时值

    sudo echo "options timeout:2" >> /etc/resolvconf/resolv.conf.d/tail

  • 添加一个DNScaching

    有几个选项我不打算覆盖。