几天以来,我在 LAN 中将 dnsmasq 设置为 192.168.1.2 上的 DNS 服务器的 Raspberry Pi 设置为 DNS 服务器。它可以帮助其他计算机通过名称找到服务器...并且运行良好,但我的 Ubuntu 18.04 笔记本电脑除外,它似乎不知何故“忘记”了服务器。
笔记本电脑启动后,一开始一切正常。从命令行 nslookup server.lan、host server.lan、ping server.lan 均给出正确结果,并且服务器上的网页打开正常。
xeros@laptop:~ $ nslookup server.lan
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: server.lan
Address: 192.168.1.3
但过了一会儿它就停止工作了。从服务器打开网站时提示无法找到,nslookup 突然失败:
xeros@laptop:~ $ nslookup server.lan
Server: 127.0.0.53
Address: 127.0.0.53#53
** server can't find server.lan: NXDOMAIN
DNS 服务器正在运行。我的智能手机或任何其他设备上都没有问题。此外,如果我指定 DNS 服务器,我的 Ubuntu 笔记本电脑上会返回正确的答案:
xeros@laptop:~ $ nslookup server.lan 192.168.1.2
Server: 192.168.1.2
Address: 192.168.1.2#53
Non-authoritative answer:
Name: server.lan
Address: 192.168.1.3
如果我重新启动笔记本电脑,一切又可以正常工作。
我不知道为什么过了一段时间后它就失败了。有人知道可能出了什么问题吗?
根据要求编辑了其他信息(在 RPi DNS 服务器上执行):
pi@raspberry:~ $ ls -al /etc/resolv.conf
-rw-r--r-- 1 root root 47 Dec 8 16:43 /etc/resolv.conf
pi@raspberry:~ $ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 127.0.0.1
pi@raspberry:~ $ cat /etc/systemd/resolved.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details
[Resolve]
#DNS=
#FallbackDNS=8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844
#Domains=
#LLMNR=yes
#DNSSEC=no
#Cache=yes
#DNSStubListener=udp
笔记本电脑也一样:
xeros@laptop:~$ ls -al /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Mai 1 2018 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
xeros@laptop:~$ cat /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 to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# 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 127.0.0.53
options edns0
xeros@laptop:~$ cat /etc/systemd/resolved.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details
[Resolve]
#DNS=
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes
答案1
在 Ubuntu 笔记本电脑上尝试一下...这是我在 AU 上的另一个答案中剪辑的...
报告...
我们需要检查您的 DNS 服务器(dnsmasq)的 /etc/resolv.conf 是否存在问题options edns0
。
/etc/resolv.conf 是一个符号链接,指向以下三个位置之一。请执行以下操作:
ls -al /etc/resolv.conf
# 注意原始符号链接设置
sudo cat /etc/resolv.conf
# 记下当前文件内容
sudo rm -i /etc/resolv.conf
# 删除符号链接
sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
# 新的符号链接
sudo cat /etc/resolv.conf
# 记下当前文件内容
使用以下方法重新测试 DNS:
host -v www.booking.com | grep -i received
# 每次使用不同的网站
sudo rm -i /etc/resolv.conf
# 删除符号链接
根据结果,您还可以尝试此符号链接:
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
# 不同的符号链接
sudo cat /etc/resolv.conf
# 记下当前文件内容
使用以下方法重新测试 DNS:
host -v www.booking.com | grep -i received
# 每次使用不同的网站
sudo rm -i /etc/resolv.conf
# 删除符号链接
如果一个符号链接比另一个更好,请暂时保留它。如果没有更好的效果,请将其设置回原始状态:
sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
# 重置为原始符号链接