静态IP配置导致apt-get错误
我在运行apt-get update
或安装新软件包时遇到错误。 虽然这仅在服务器配置为静态IP地址时发生。 将配置更改回DHCP并重新启动网络可以解决问题,尽管我需要静态IP。 一旦它工作,我可以改回我的静态IP地址并重新启动网络。 虽然这只有在我重新启动服务器(重新启动路由器没问题)之后才有效,然后我开始得到相同的错误并且必须切换回DHCP。
关于可能导致此问题的任何想法或对其进行故障排除的提示? 提前致谢。
-
这是我的静态IP配置:
auto eth0 iface eth0 inet static address 192.168.2.2 netmask 255.255.255.0 gateway 192.168.2.1
-
apt-get update
错误是这样的:其中一些
Ign http://us.archive.ubuntu.com precise-backports InRelease
然后很多这些
Err http://security.ubuntu.com precise-security Release.gpg Something wicked happened resolving 'security.ubuntu.com:http' (-5 - No address associated with hostname)
还有很多这些
W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/precise-backports/universe/i18n/Translation-en Something wicked happened resolving 'us.archive.ubuntu.com:http' (-5 - No address associated with hostname)
听起来您无法通过DNS解析域名。 假设是这种情况,您可以通过向/etc/network/interfaces
添加dns-nameservers
行来修复它
auto eth0 iface eth0 inet static address 192.168.2.2 netmask 255.255.255.0 gateway 192.168.2.1 dns-nameservers 192.168.2.1
然后跑
resolvconf -u
以root身份更新/etc/resolv.conf
。 随意包含DNS搜索域记录(通常也通过DHCP发布)。 有关更多信息,请参阅resolvconf(8) 。
值得注意的是,您可能需要在更改/etc/network/interfaces
后重新启动网络:
sudo /etc/init.d/networking restart