我在 192.168.0.4 上运行了 DNSMasq。它将 nino-nas 映射到 192.168.0.7。但是,我必须手动请求 DNS 查找才能使其正常工作。我的 DNS 条目似乎配置正确:
nino@nino-ubuntu:~$ nmcli device show enp38s0 | grep IP4.DNS
IP4.DNS[1]: 192.168.0.4
IP4.DNS[2]: 185.37.37.37
但主机名尚未解析:
nino@nino-ubuntu:~$ ping nino-nas
ping: unknown host nino-nas
手动请求 DNS 查找:
nino@nino-ubuntu:~$ dig nino-nas
; <<>> DiG 9.10.3-P4-Ubuntu <<>> nino-nas
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29058
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0,
ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;nino-nas. IN A
;; ANSWER SECTION:
nino-nas. 0 IN A 192.168.0.7
;; Query time: 0 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Tue Jul 18 23:54:34 CEST 2017
;; MSG SIZE rcvd: 53
服务器 IP:127.0.1.1。看来我们已经有了映射,不需要从 192.168.0.4 请求它?现在相同的 ping 命令有效:
nino@nino-ubuntu:~$ ping nino-nas
PING nino-nas (192.168.0.7) 56(84) bytes of data.
64 bytes from nino-nas (192.168.0.7): icmp_seq=1 ttl=64 time=0.224 ms
64 bytes from nino-nas (192.168.0.7): icmp_seq=2 ttl=64 time=0.283 ms
64 bytes from nino-nas (192.168.0.7): icmp_seq=3 ttl=64 time=0.249 ms
可能是什么问题?Ubuntu 版本:16.04
内容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
内容/etc/network/interfaces
:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
请注意,网络中的其他设备也难以解析这些名称。在我的 TP-Link 路由器中,我已在 DHCP 设置中将 192.168.0.4 设置为主 DNS。
更新 @derHugo:我似乎正在使用 Network-Manager,它是自 15.04 以来的默认设置ubuntu 文档。
/etc/NetworkManager/NetworkManager.conf:
[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq
[ifupdown]
managed=false