问题:

问题:

问题:

运行 Ubuntu 17.10

我已经尝试解决(呵呵)这个问题大约一周了,尽管进行了无数次 Google 搜索和大约 20 次不同的尝试,但我无法阻止 dnsmasq 定期导致我的 CPU 因以下违规者而飙升约一分钟:

  • systemd-resolved
  • systemd-journald
  • dnsmasq

监控journalctl -f每次发生时我都会看到这样的情况:

已达到最大并发 DNS 查询数 (150)

伴随/之前是对某个域(通常是 ubuntu 连接检查)的疯狂请求循环,如下所示:

query[A] connectivity-check.ubuntu.com from 127.0.0.1
forwarded connectivity-check.ubuntu.com to 127.0.1.1
forwarded connectivity-check.ubuntu.com to 127.0.0.53
query[A] connectivity-check.ubuntu.com from 127.0.0.1
forwarded connectivity-check.ubuntu.com to 127.0.0.53
query[AAAA] connectivity-check.ubuntu.com from 127.0.0.1
forwarded connectivity-check.ubuntu.com to 127.0.0.53
query[AAAA] connectivity-check.ubuntu.com from 127.0.0.1
forwarded connectivity-check.ubuntu.com to 127.0.0.53
query[A] connectivity-check.ubuntu.com from 127.0.0.1
forwarded connectivity-check.ubuntu.com to 127.0.0.53
query[AAAA] connectivity-check.ubuntu.com from 127.0.0.1
forwarded connectivity-check.ubuntu.com to 127.0.0.53

我发现改变我的/etc/resolv.conf使用nameserver 127.0.0.53会使尖峰几乎立即消散。

但是,由于网络管理器会定期更新该文件,因此我必须大约每小时执行一次。


配置:

/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
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 127.0.0.1
search fios-router.home

/etc/NetworkManager/NetworkManager.conf

[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=false

[device]
wifi.scan-rand-mac-address=no

/etc/dnsmasq.conf

// All default except this at the very end for my wildcard DNS
address=/asmar.d/127.0.0.1

/run/dnsmasq/resolv.conf

nameserver 127.0.0.53

/run/resolvconf/接口:

lo.dnsmasq:

nameserver 127.0.0.1

systemd-resolved:

nameserver 127.0.0.53

/etc/resolvconf/接口顺序:

# interface-order(5)
lo.inet6
lo.inet
lo.@(dnsmasq|pdnsd)
lo.!(pdns|pdns-recursor)
lo
tun*
tap*
hso*
em+([0-9])?(_+([0-9]))*
p+([0-9])p+([0-9])?(_+([0-9]))*
@(br|eth)*([^.]).inet6
@(br|eth)*([^.]).ip6.@(dhclient|dhcpcd|pump|udhcpc)
@(br|eth)*([^.]).inet
@(br|eth)*([^.]).@(dhclient|dhcpcd|pump|udhcpc)
@(br|eth)*
@(ath|wifi|wlan)*([^.]).inet6
@(ath|wifi|wlan)*([^.]).ip6.@(dhclient|dhcpcd|pump|udhcpc)
@(ath|wifi|wlan)*([^.]).inet
@(ath|wifi|wlan)*([^.]).@(dhclient|dhcpcd|pump|udhcpc)
@(ath|wifi|wlan)*
ppp*
*

systemd-resolve --status:

Global
         DNS Servers: 127.0.0.1
          DNSSEC NTA: 10.in-addr.arpa
                      16.172.in-addr.arpa
                      168.192.in-addr.arpa
                      17.172.in-addr.arpa
                      18.172.in-addr.arpa
                      19.172.in-addr.arpa
                      20.172.in-addr.arpa
                      21.172.in-addr.arpa
                      22.172.in-addr.arpa
                      23.172.in-addr.arpa
                      24.172.in-addr.arpa
                      25.172.in-addr.arpa
                      26.172.in-addr.arpa
                      27.172.in-addr.arpa
                      28.172.in-addr.arpa
                      29.172.in-addr.arpa
                      30.172.in-addr.arpa
                      31.172.in-addr.arpa
                      corp
                      d.f.ip6.arpa
                      home
                      internal
                      intranet
                      lan
                      local
                      private
                      test

Link 5 (br-b1f5461ac410)
      Current Scopes: none
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no

Link 4 (docker0)
      Current Scopes: none
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no

Link 3 (wlp62s0)
      Current Scopes: none
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no

Link 2 (enp61s0)
      Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
         DNS Servers: 8.8.8.8
                      8.8.4.4
                      ::1

问题:

如何在仍然使用我的通配符域名的情况下解决此问题?

选修的:使用 Google DNS 时如何实现此目的?

请不要建议增加并发 DNS 查询。那不是一个解决方案。


解决了!

请参阅 telcoM 的 DNS 速成课程(已接受的答案),它引导我找到了解决方案

当我尝试从该答案中获得的知识时,请参阅我的后续和最终解决方案

答案1

看起来您可能dnsmasq在 127.0.0.1 中有进程,systemd-resolved在 127.0.0.53 中有进程,相互之间来回传递查询,从而导致循环。即使dnsmasq单独也可能能够循环,因为默认情况下它会/etc/resolv.conf查找真正的 DNS 服务器以用于它没有信息的名称。

您的 DNS 配置可能有很多层:

  • 首先,您可以通过 DHCP 或类似方式从 ISP 获取 DNS 服务器信息。
  • 然后,NetworkManager可以将其配置为覆盖信息并使用它dnsmasq,但目前尚未以这种方式配置。
  • 相反,NetworkManager配置为使用该resolvconf工具来更新真实的/etc/resolv.conf.并且dnsmasq可能包括一个嵌入式配置,用于resolvconf覆盖 DHCP 接收到的任何 DNS 服务,并在dnsmasq运行时使用 127.0.0.1。
  • systemd-resolved 还可能包含 的嵌入式配置resolvconf,但显然被 覆盖dnsmasq

我还不明白 127.0.1.1 和 127.0.0.53 是从哪里来的。dnsmasqUbuntu 的默认配置中是否提到了它们?

正如 的评论中所述/etc/resolv.conf,运行此命令以查看有关systemd-resolved配置的更多信息:

systemd-resolve --status

另请检查目录的内容:该工具收集从各种来源获取的所有 DNS 服务器信息的/run/resolvconf/interface/位置。resolvconf/etc/resolvconf/interface-order确定检查每个源的顺序,直到遇到环回地址或已列出实际的 3 个 DNS 服务器/etc/resolv.conf

由于您要用来dnsmasq设置通配符域,因此您需要保留127.0.0.1-/etc/resolv.conf但您需要配置dnsmasq为不使用该文件,而是从其他地方获取它应该使用的 DNS 服务器。

如果/run/NetworkManager/resolv.conf包含通过 DHCP 从 ISP 获取的 DNS 服务器,您可以dnsmasq通过将此行添加到其配置中来轻松使用它:

resolv-file=/run/NetworkManager/resolv.conf

这告诉dnsmasq我们从哪里获取它还不知道的 DNS 信息。因此,如果您想使用 Google DNS,您可以dnsmasq配置

resolv-file=/etc/google-dns-resolv.conf

并将 Google DNS 的 DNS 配置行以通常的格式放入/etc/google-dns-resolv.conf.

答案2

使用 dnsmasq 配置修复了我的 dnsmasq systemd-resolve 竞赛。

  1. 使用 systemd-resolve (127.0.0.53) 作为外部 dns,因为它具有 dnssec 功能并具有根服务器。
  2. 仅将 dnsmasq 绑定到某些静态配置的环回,如果我需要 dhcp,可以添加更多接口。

/etc/dnsmasq.d/myconfig

#PES 20180808 dnsmasq and systemd-resolve conflict.
# dont use /etc/resolv.conf, go direct to systemd-resolve, only bind to lo
no-resolv
bind-interfaces
interface=lo
server=127.0.0.53

答案3

在 Ubuntu 18.04 上

1 - 创建 /etc/google-dns-resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4

2 - 创建配置文件 /etc/dnsmasq.d/my_dnsmaq.conf

resolv-file=/etc/google-dns-resolv.conf

3 - 插入到 /etc/default/dnsmasq 的底部

IGNORE_RESOLVCONF=yes

4 - 最后,重新启动 dnsmasq 服务

sudo service dnsmasq restart


我用过约翰尼的回答上面但是我的答案中缺少第 3 步,以便正确读取我的 dnsmasq 配置文件。谢谢

答案4

当我尝试各种解决方案时,我最初将其记录为问题的一部分。为了清楚起见,已将其从该问题剪切/粘贴到该答案中,但如果没有中提供的见解,该答案就不是独立的电信公司的回答

解决方案:

我根据以下内容进行了更改电信公司下面的建议。

创建/etc/google-dns-resolv.conf内容:

nameserver 8.8.8.8
nameserver 8.8.4.4

添加resolv-file=/etc/google-dns-resolv.conf/etc/dnsmasq.conf

进行更改并运行后,sudo service dnsmasq restartCPU 仍然飙升,但现在rsyslogd已进入违规者的行列。大约一分钟后它就稳定下来了,但我再也看不到127.0.1.1journalctl -f

更新:大约 10 分钟后,CPU 再次飙升:

在此输入图像描述

更新#2:谢谢电信公司下面是精彩的小型 DNS 速成课程,我对它的来源持怀疑态度127.0.0.53,我深入研究了一下(请参阅我对他的答案的评论),发现它来自/run/dnsmasq/resolv.conf,其中有内容nameserver 127.0.0.53。我决定将内容更新为nameserver 127.0.0.1.现在,我看到输出的唯一 IP 地址journalctl -f127.0.0.1,并且从那以后就没有经历过 CPU 峰值(现在大约持续 10 分钟;这至少与我的 CPU 之前享受的任何休息时间一样长)!

[已解决] 更新#3:使用127.0.0.1/run/dnsmasq/resolv.conf太愚蠢了。它完全破坏了我的 DNS 解析(一开始它似乎可以工作,因为我只访问缓存的 DNS)。切换到使用 Google 域名服务器 ( 8.8.8.8& 8.8.4.4) 后,DNS 解析再次正常工作,我的通配符域继续工作,并且我没有遇到 CPU 峰值。当我执行典型的日常活动并相应地再次更新时,我将在大约一个小时内观察它的表现;希望与解决了

更新#4:现在似乎可以按照以下步骤解决这个问题更新 #3。谢谢电信公司感谢所有引导我走向正确方向的出色细节。赏金将在 15 小时内发放。

相关内容