Ubuntu 19.04 中的 DNS 问题

daf*_*fan 5 networking dns 19.04

我最近将我的笔记本电脑升级到 19.04(以前是 18.04),从那时起我在 DNS 解析方面遇到了问题。

解析任何地址只需要 15 秒。例如,这里是命令“ping www.google.ch”的wireshark跟踪,它显示了DNS解析中的不稳定行为(抱歉粘贴了日志blob):

  1 0.000000000    127.0.0.1             127.0.0.53            DNS      82     Standard query 0x9885 A google.ch OPT
  2 0.000040848    127.0.0.1             127.0.0.53            DNS      82     Standard query 0xf398 AAAA google.ch OPT
  3 0.000472315    192.168.1.61          192.168.1.1           DNS      71     Standard query 0xbc08 A google.ch
  4 0.000751989    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
  5 0.003821221    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
  6 0.004064023    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
  7 0.005267971    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
  8 0.005497112    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
  9 0.006644819    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 10 0.006863866    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 11 0.007920878    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 12 0.008130719    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 13 0.009242334    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 14 0.009637573    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 15 0.010792517    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 16 0.011031800    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 17 0.012258637    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 18 0.012489432    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 19 0.013713170    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 20 0.013915614    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 21 0.014032986    192.168.1.1           192.168.1.61          DNS      87     Standard query response 0xbc08 A google.ch A 172.217.168.35
 22 0.014322592    127.0.0.53            127.0.0.1             DNS      98     Standard query response 0x9885 A google.ch A 172.217.168.35 OPT
 23 0.015102484    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 24 0.015277122    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 25 0.016431079    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 26 0.016609622    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 27 0.017757978    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 28 0.017919223    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 29 0.018984296    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 30 0.019164206    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 31 0.020291847    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 32 0.020465090    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 33 0.021606042    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 34 0.021834229    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 35 0.022902638    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 36 0.023076859    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 37 0.024185348    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 38 0.024369468    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 39 0.025402235    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 40 0.025557918    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 41 0.026557335    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 42 0.026681040    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 43 0.027705800    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 44 0.027808876    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 45 0.028793187    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 46 0.028893739    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 47 0.029878670    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 48 0.029986119    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 49 0.031010405    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 50 0.031127410    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 51 0.032151807    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 52 0.032261394    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x335e AAAA google.ch
 53 0.033290733    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x335e Refused AAAA google.ch
 54 5.001947117    127.0.0.1             127.0.0.53            DNS      82     Standard query 0x9885 A google.ch OPT
 55 5.002322889    127.0.0.53            127.0.0.1             DNS      98     Standard query response 0x9885 A google.ch A 172.217.168.35 OPT
 56 5.002450775    127.0.0.1             127.0.0.53            DNS      82     Standard query 0xf398 AAAA google.ch OPT
 57 5.002829396    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 58 5.005749595    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 59 5.006000720    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 60 5.007085084    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 61 5.007278137    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 62 5.008493792    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 63 5.008726953    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 64 5.009760440    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 65 5.009962097    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 66 5.011064276    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 67 5.011294755    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 68 5.012464702    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 69 5.012696487    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 70 5.013803847    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 71 5.013991838    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 72 5.015081146    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 73 5.015311695    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 74 5.016397601    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 75 5.016572805    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 76 5.018326688    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 77 5.018522763    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 78 5.019673004    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 79 5.019905288    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 80 5.020942721    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 81 5.021117750    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 82 5.022175880    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 83 5.022368879    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 84 5.023497195    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 85 5.023727693    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 86 5.024716756    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 87 5.024917772    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 88 5.025940891    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 89 5.026242405    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 90 5.027396468    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 91 5.027627309    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 92 5.028669617    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 93 5.028844156    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 94 5.029909396    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 95 5.030099489    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 96 5.031241631    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 97 5.031470878    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
 98 5.032507283    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
 99 5.032684260    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
100 5.033712152    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
101 5.033923324    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
102 5.035076891    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
103 5.035307433    192.168.1.61          192.168.1.1           DNS      71     Standard query 0x897a AAAA google.ch
104 5.036458185    192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x897a Refused AAAA google.ch
105 10.005946641   127.0.0.1             127.0.0.53            DNS      82     Standard query 0x9885 A google.ch OPT
106 10.006376461   127.0.0.53            127.0.0.1             DNS      98     Standard query response 0x9885 A google.ch A 172.217.168.35 OPT
107 10.006552675   127.0.0.1             127.0.0.53            DNS      82     Standard query 0xf398 AAAA google.ch OPT
108 10.006923636   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
109 10.009568741   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
110 10.009795245   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
111 10.010954209   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
112 10.011184364   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
113 10.012458263   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
114 10.012691547   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
115 10.013805929   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
116 10.014036944   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
117 10.015165110   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
118 10.015403914   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
119 10.016501372   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
120 10.016710396   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
121 10.017809472   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
122 10.017988063   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
123 10.019114116   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
124 10.019353925   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
125 10.020505187   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
126 10.020741642   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
127 10.021814158   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
128 10.022045574   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
129 10.023153608   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
130 10.023336649   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
131 10.024412807   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
132 10.024632391   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
133 10.025813396   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
134 10.026244008   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
135 10.027357668   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
136 10.027535923   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
137 10.028599634   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
138 10.028776517   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
139 10.029782946   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
140 10.029961443   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
141 10.031008052   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
142 10.031186821   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
143 10.032214660   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
144 10.032393053   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
145 10.033518425   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
146 10.033744680   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
147 10.034887325   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
148 10.035116833   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
149 10.036226120   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
150 10.036458904   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
151 10.037515996   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
152 10.037775347   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
153 10.038839704   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
154 10.039017849   192.168.1.61          192.168.1.1           DNS      71     Standard query 0x2b09 AAAA google.ch
155 10.040061077   192.168.1.1           192.168.1.61          DNS      71     Standard query response 0x2b09 Refused AAAA google.ch
156 15.024825964   127.0.0.1             127.0.0.53            DNS      100    Standard query 0xb4e4 PTR 35.168.217.172.in-addr.arpa OPT
157 15.025320672   192.168.1.61          192.168.1.1           DNS      89     Standard query 0x0774 PTR 35.168.217.172.in-addr.arpa
158 15.038823507   192.168.1.1           192.168.1.61          DNS      127    Standard query response 0x0774 PTR 35.168.217.172.in-addr.arpa PTR zrh04s14-in-f3.1e100.net
159 15.039215285   127.0.0.53            127.0.0.1        

hey*_*ema 1

从评论中...

的符号链接/etc/resolv.conf设置为/run/systemd/resolve/stub-resolv.conf包含options edns0. 某些网络不响应此 DNS 扩展,并且 DNS 解析会中断。

我们使用以下命令重置符号链接:

sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
Run Code Online (Sandbox Code Playgroud)

这可能也有效:

sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
Run Code Online (Sandbox Code Playgroud)

后记:

您可能还遇到的一个问题是 DSL 连接的 MTU 设置。

Ubuntu 的网络配置中有一个 MTU 设置,路由器中有一个 WAN MTU 设置。

对于 DSL,常见的 MTU 设置是 1492。首先尝试该值,看看您的网站现在是否可以访问。

要确定正确的设置,请从所有 MTU 设置 = 1500 和 VPN = 关闭开始。(VPN 需要不同的测试)。

在终端中:

ping [-c count] [-M do] [-s packet_size] [host]
Run Code Online (Sandbox Code Playgroud)

使用的选项是:

  • c count: ping 的次数
  • M hint:选择路径MTU发现策略。可以是do(禁止分段,甚至是本地分段)、want(进行 PMTU 发现,当数据包大小较大时在本地分段)或dont(不设置 DF 标志)。
  • s packet_size:指定要发送的数据字节数。

您应该始终从 1472 开始,每次递减 10。一旦收到回复,就加 1,直到收到碎片数据包。取该值(最后一个有效值)并将该值加上 28 以考虑各种 TCP/IP 标头。例如。假设 1452 是正确的数据包大小(您首先收到对 ping 的 ICMP 回复)。实际 MTU 大小为 1480,这是我们正在使用的网络的最佳值。

ping -c 4 -M do -s 1472 8.8.8.8 # this will probably show fragmentation

ping -c 4 -M do -s 1462 8.8.8.8 # may show fragmentation

ping -c 4 -M do -s 1452 8.8.8.8 # no fragmentation?

ping -c 4 -M do -s 1453 8.8.8.8 # still no fragmentation?
Run Code Online (Sandbox Code Playgroud)

参考:如何使用 ICMP ping 确定正确的 MTU 大小