Ubuntu:如何在 /etc/network/interfaces 中为 resolvconf 正确配置 DNS 服务器?

0xC*_*22L 18 networking ubuntu dns resolvconf

我看到的所有配置示例 ( /etc/network/interfaces) 都表明您配置了一个接口,然后在下面给出了如下dns-*几行:

auto eth0
iface eth0 inet static
        ...
        dns-nameservers 127.0.0.2
        dns-search example.com my.example.com
Run Code Online (Sandbox Code Playgroud)

现在我知道 DNS 协议独立于传输机制。因此,dns-nameservers在线上添加 IPv6 地址本身不应该是错误的。

但是,因为无论如何我也在为 IPv6 配置接口,所以在dns-nameservers那里添加行是有意义的:

iface eth0 inet6 static
        ...
        dns-nameservers ::2
        dns-search example.com my.example.com
Run Code Online (Sandbox Code Playgroud)

……还是做到了?因为在resolvconf创建时/etc/resolv.conf它会忽略所有 IPv6 DNS 服务器。它似乎也忽略了dns-searchdns-domain。它似乎尊重的唯一一行是dns-nameservers来自 IPv4 配置的行eth0

配置DNS服务器的正确方法是什么?


关于为什么它应该成为每个相应iface节的一部分的进一步间接证据。引自man 8 resolvconf

ifup(8) 程序可用于根据 中的设置配置网络接口/etc/network/interfaces(5)。为了ifup推动域名服务器信息resolvconf时,它配置的接口,添加dns-行相关iface的节 /etc/network/interfaces。要添加名称服务器地址,请添加一行以dns-nameservers.

jdt*_*ood 10

将 dns-* 选项放在iface eth0 inet static节或iface eth0 inet6 static节中是正确的。当它们所属的逻辑接口定义变为活动时,这些选项变为活动状态。

我刚刚在我自己的 Ubuntu 15.04 机器上测试了这个,我通常用 DHCP 配置。我禁用了 NetworkManager 并编辑了 /etc/network/interfaces 使其看起来像这样:

iface eth0 inet static
        address 192.168.178.22
        netmask 255.255.255.0
        dns-nameservers 8.8.8.8
        dns-search foo

iface eth0 inet6 static
        address fe80::390:f5ff:fef7:96b9/64
        dns-nameservers ::2
        dns-search bar
Run Code Online (Sandbox Code Playgroud)

然后我做了

$ sudo ifup eth0
Run Code Online (Sandbox Code Playgroud)

结果:

$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:90:f5:f7:96:b9  
      inet addr:192.168.178.22  Bcast:192.168.178.255  Mask:255.255.255.0
      inet6 addr: fe80::390:f5ff:fef7:96b9/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:2114609 errors:0 dropped:1 overruns:0 frame:0
      TX packets:1757693 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:2033346950 (2.0 GB)  TX bytes:1318685445 (1.3 GB)
      Interrupt:20 Memory:f7e00000-f7e20000 

$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver ::2
nameserver 8.8.8.8
search bar foo
Run Code Online (Sandbox Code Playgroud)

请注意,这两个节中的地址、dns-nameservers 和 dns-search 选项现在都处于活动状态。

[2015 年 5 月 30 日更新]