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

ken*_*ntz 17 networking dns dhcp 12.04

在将我的计算机配置为使用静态 ip 时,我遇到了 Ubuntu 12.04 服务器版中的名称解析问题。

在 /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
Run Code Online (Sandbox Code Playgroud)

运行$ 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)
[...]
Run Code Online (Sandbox Code Playgroud)

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

auto eth0
iface eth0 inet dhcp
Run Code Online (Sandbox Code Playgroud)

一切正常。

查看 /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?是否有特定的包可以查看未解决的问题?

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

ukj*_*ola 16

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

dns-nameservers [IP address(es) of your DNS]     
dns-search      [your dns-search strings (optional)]
Run Code Online (Sandbox Code Playgroud)