当前位置: 首页>>技术教程>>正文


当网络配置为静态 IP 时,resolv.conf 不会在重新启动时设置

, , ,

问题描述

当我将计算机配置为使用静态 IP 时,我在 Ubuntu 12.04 Server 版本中遇到了似乎是名称解析问题。

在 /etc/network/interfaces 中:

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.28
netmask 255.255.255.0
gateway 192.168.1.1

运行 $ sudo apt-get upgrade 会导致“无法获取…”:

. . . W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/precise-backports/universe/i18n/Translation-en_US Something wicked happened resolving 'us.archive.ubuntu.com:http' (-5 - No address associated with hostname)
[...]

当我将 /etc/network/interfaces 更改为:

auto eth0
iface eth0 inet dhcp

一切正常。

查看 /etc/resolv.conf 可以提供更多提示。

在我遇到解决问题的情况下,resolv.conf 是空的;未指定名称服务器。然后我从静态更改为 DHCP 并重新启动网络; /etc/resolv.conf 更改为:’nameserver 192.168.1.1’。

从 DHCP 切换回静态并重新启动不会删除名称服务器条目。但是当我使用静态设置重新启动系统时,resolv.conf 为空。当我使用 DHCP 设置重新启动系统时,resolv.conf 的名称服务器为 192.168.1.1。那么,问题似乎是resolve.conf 没有被正确写入?哪个包/代码负责写入 resolv.conf?是否有一个特定的包可供我查看未解决的问题?

更新:\nistream 发布了一篇很好的文章,讨论了 12.04 中对resolve.conf 的更改。\n http://www.stgraber.org/2012/02/24/dns-in-ubuntu-12-04/

最佳回答

根据 the resolvconf man page(手册页中提供的示例),将以下内容添加到静态配置下的 /etc/network/interfaces 中:

dns-nameservers [IP address(es) of your DNS]     
dns-search      [your dns-search strings (optional)]

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/14311.html,未经允许,请勿转载。