如何在 Ubuntu 16.10 中配置本地 DNS 查找?

如何在 Ubuntu 16.10 中配置本地 DNS 查找?

我刚刚安装了 Ubuntu 16.10,并将我之前的主目录从 kubuntu 16.04 备份到我的新安装中。一切运行正常,但尽管反复尝试,我还是无法解析本地地址。

所有网络似乎都运行正常。互联网浏览、外部地址的 DNS 查找、ssh 等都很棒。在本地,我可以通过 ssh 使用地址访问机器,但不能使用名称。在 nautilus/samba 中,一切都运行正常,这意味着 WINS 可以正常工作。唯一的问题似乎是本地网络 DNS。我已安装并运行 avahi-daemon,因为它是 Ubuntu 自带的。

我已经进行了一些故障排除,使用<<>>来缩短冗余或正常工作的部分。

$ nmcli g
STATE      CONNECTIVITY  WIFI-HW  WIFI     WWAN-HW  WWAN    
connected  full          enabled  enabled  enabled  enabled 

$ ping tendril8 << or tendril8.local >>
ping: tendril8: Name or service not known

$ ping gateway
PING gateway (192.168.1.1) 56(84) bytes of data.
64 bytes from gateway (192.168.1.1): icmp_seq=1 ttl=64 time=4.16 ms

$ ping askubuntu.com
PING askubuntu.com (151.101.129.69) 56(84) bytes of data.
64 bytes from 151.101.129.69 (151.101.129.69): icmp_seq=1 ttl=49 time=43.0 ms

$ nslookup askubuntu.com
Server:     127.0.1.1
Address:    127.0.0.1#53
<< followed by several IP addresses >>

$ nslookup tendril8 << or tendril8.local >>
Server:     127.0.1.1
Address:    127.0.0.1#53
** server can't find tendril8: NXDOMAIN

$ 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 127.0.1.1

$ ls -la /etc/resolv.conf
lrwxrwxrwx 1 root root 29 Oct 15 19:30 /etc/resolv.conf -> ../run/resolvconf/resolv.conf

$ cat /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat
gshadow:        files

hosts:          files resolve [!UNAVAIL=return] mdns4_minimal dns [NOTFOUND=return]
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

注意:在 Ubuntu 16.10 中切换到 systemd.resolved 之前,我花了大量时间研究“较旧”的解决方案。它们对我不起作用,我不认为这是与以前的 Ubuntu 配置中的类似问题重复的问题。

答案1

如果我正确理解了您的问题,您无法解析本地主机名。

对此,我在全新安装 16.10 时遇到了同样的问题,结果发现这是一个已知问题(https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1624071) 与 systemd 中的 libnss-resolve 相关。

对我来说,解决方案是检查你的 /etc/nsswitch.conf 文件,并特别注意 NSS 如何解析你的主机:

hosts: files resolve [!UNAVAIL=return] mdns4_minimal [NOTFOUND=return] dns myhostname

这种逻辑似乎在到达 mDNS 之前就导致主机名解析失败。

将主机行编辑回 16.10 之前的版本可以修复这个明显的逻辑错误:

hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname

所包含的错误报告链接表明 systemd 包的未来版本最终可能会解决此问题。

富有的

答案2

自动编辑的另一种解决方案/etc/nsswitch.conf是删除[编辑:并重新安装] libnss-resolve

sudo apt purge libnss-resolve
sudo apt install libnss-resolve

答案3

我在全新安装 Ubuntu 17.04 时遇到了这个问题。我选择在笔记本电脑上从使用 systemd-resolved 切换到 dnsmasq(名称服务器也使用 dnsmasq)。我按照如何禁用 systemd-resolved 并使用 dnsmasq 解析 DNS?

相关内容