![resolvconf 应如何处理 /etc/network/interfaces 中的多个接口](https://linux22.com/image/1060189/resolvconf%20%E5%BA%94%E5%A6%82%E4%BD%95%E5%A4%84%E7%90%86%20%2Fetc%2Fnetwork%2Finterfaces%20%E4%B8%AD%E7%9A%84%E5%A4%9A%E4%B8%AA%E6%8E%A5%E5%8F%A3.png)
我使用的是全新的 Ubuntu 16.04.02 LTS,在安装时我分配了它address 192.168.0.151
,dns-nameservers 192.168.0.10 192.168.0.11
并且dns-search example.com
。
因此安装并重启后我得到了/etc/network/interfaces
如下内容:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens18
iface ens18 inet static
address 192.168.0.151
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 192.168.0.10 192.168.0.11
dns-search example.com
并/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 192.168.100.10
nameserver 192.168.100.11
search favoptic.com
一切都很好,并且按预期工作!但现在我想添加 2VIP 地址(虚拟 IP 地址或别名),因此我添加了以下内容/etc/network/interfaces
而不改变任何已经存在的内容(仅添加):
auto ens18:0
iface ens18 inet static
address 192.168.0.152
netmask 255.255.255.0
auto ens18:1
iface ens18 inet static
address 192.168.0.153
netmask 255.255.255.0
重启后,主机上现在有 3 个工作 IP。
但现在/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
因此 DNS 解析不再起作用。例如:
$ ping askubuntu.com
ping: unknown host askubuntu.com
我有另一台安装了 Ubuntu 14.04.5 LTS 的主机,并且我在那里设置了类似的接口和 IP,并且一切都运行正常!
解决方案
如果我将dns-nameservers
和添加dns-search
到两个 vip 定义中,它就会起作用,但似乎有点多余。这是一个错误还是这样设计只是为了让我困惑?