Dev*_*uce 4 domain-name-system resolv.conf ubuntu-18.04 netplan
我这个周末更新了内核,现在使用的是 5.3.1。
christopher@HAL4:~$ uname -r
5.3.1-050301-generic
Run Code Online (Sandbox Code Playgroud)
我需要登录服务器,但我无法再通过主机名登录。例如,我有一个服务器“web4”,它的本地 IP 是 192.168.64.140。如果我运行挖掘:
christopher@HAL4:~$ dig web4
; <<>> DiG 9.11.3-1ubuntu1.9-Ubuntu <<>> web4
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1580
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1280
;; QUESTION SECTION:
;web4. IN A
;; ANSWER SECTION:
web4. 0 IN A 192.168.64.140
;; Query time: 0 msec
;; SERVER: 192.168.3.222#53(192.168.3.222) <---- Correct!
;; WHEN: Mon Sep 30 09:50:31 CDT 2019
;; MSG SIZE rcvd: 49
Run Code Online (Sandbox Code Playgroud)
nslookup 也是如此:
christopher@HAL4:~$ nslookup web4
Server: 192.168.3.222
Address: 192.168.3.222#53
Name: web4
Address: 192.168.64.140
Run Code Online (Sandbox Code Playgroud)
但是, ping 或 ssh 都不起作用(“登录”是使用我的密钥的 bash 脚本):
christopher@HAL4:~$ ping web4
ping: web4: Name or service not known
christopher@HAL4:~$ login web4
ssh: Could not resolve hostname web4: Name or service not known
Run Code Online (Sandbox Code Playgroud)
我的 /etc/resolv.conf 是:
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 192.168.3.222
nameserver 192.168.70.80
Run Code Online (Sandbox Code Playgroud)
它是 /run/systemd/resolve/resolv.conf 的符号链接。
这是我的 /etc/netplan/01-network-manager-all.yaml 文件:
christopher@HAL4:~$ cat /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
enp4s0:
dhcp4: no
addresses: [192.168.2.47/19]
gateway4: 192.168.1.1
nameservers:
addresses: [192.168.3.222,192.168.70.80]
Run Code Online (Sandbox Code Playgroud)
我的 DNS 发生了什么?!
查看/etc/nsswitch.conf
寻找起始行hosts并确保它在dns上面。
hosts: files dns
Run Code Online (Sandbox Code Playgroud)
更新 - 正如您在评论中所说,您的 nsswitch.conf 有:
hosts: files mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns myhostname
Run Code Online (Sandbox Code Playgroud)
这意味着主机解析将首先查看/etc/hosts,然后使用mdns4_minimal,这意味着您正在使用avahi守护进程服务,也许它没有运行?如果使用 mdns 解析失败,主机解析将会失败 - 这通常是设计使然,以确保解析一定使用 avahi,事实上,您在resolve [!UNAVAIL=return]此之后得到的事实意味着 systemd 解析器也可能被配置...[!UNAVAILBLE=return]意味着如果 systemd-resolved 已启动,则将始终使用该系统,但如果未启动,则继续使用 nss-dns。因此,确定您想要如何将名称解析为地址,如果您不使用 mdns,您可以删除,mdns4_minimal [NOTFOUND=return]这样这可能对您更好:
hosts: files resolve [!UNAVAIL=return] dns myhostname
Run Code Online (Sandbox Code Playgroud)
甚至:
hosts: files dns myhostname
Run Code Online (Sandbox Code Playgroud)