pymumu / smartdns

A local DNS server to obtain the fastest website IP for the best Internet experience, support DoT, DoH. 一个本地DNS服务器,获取最快的网站IP,获得最佳上网体验,支持DoH,DoT。
https://pymumu.github.io/smartdns/
GNU General Public License v3.0
7.92k stars 1.05k forks source link

无法获取新域名的 #1758

Closed scruel closed 3 days ago

scruel commented 2 weeks ago

问题现象
新增域名无法获取到 IP 记录

运行环境

version: '3'

services:
  smartdns:
    container_name: smartdns
    image: pymumu/smartdns:latest
    restart: always
    network_mode: host
    volumes:
      - ./:/etc/smartdns

重现步骤

bind [::]:53

log-level debug
log-size 64K

speed-check-mode none
cache-persist no
server 1.1.1.1

本机配置 dns 服务器到 smartdns, 新增上游域名 test5m1.scruel.com,随后执行 dig @1.1.1.1,可见解析的 IP 地址,随后执行 dig,无法获取到包含 IP 地址的记录:

$ dig test5m1.scruel.com @1.1.1.1

; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> test5m1.scruel.com @1.1.1.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18606
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;test5m1.scruel.com.            IN      A

;; ANSWER SECTION:
test5m1.scruel.com.     300     IN      A       1.2.3.4

;; Query time: 189 msec
;; SERVER: 1.1.1.1#53(1.1.1.1) (UDP)
;; WHEN: Mon Jun 17 18:39:13 CST 2024
;; MSG SIZE  rcvd: 63

$ dig test5m1.scruel.com

; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> test5m1.scruel.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 8729
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;test5m1.scruel.com.            IN      A

;; AUTHORITY SECTION:
test5m1.scruel.com.     1484    IN      SOA     carol.ns.cloudflare.com. dns.cloudflare.com. 2344105775 10000 2400 604800 1800

;; Query time: 0 msec
;; SERVER: 127.0.0.42#53(127.0.0.42) (UDP)
;; WHEN: Mon Jun 17 18:39:19 CST 2024
;; MSG SIZE  rcvd: 96

重启该 docker 容器,再次执行 dig,又变得可获取到了:

$ dig test5m1.scruel.com

; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> test5m1.scruel.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22398
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;test5m1.scruel.com.            IN      A

;; ANSWER SECTION:
test5m1.scruel.com.     600     IN      A       1.2.3.4

;; Query time: 229 msec
;; SERVER: 127.0.0.42#53(127.0.0.42) (UDP)
;; WHEN: Mon Jun 17 18:43:54 CST 2024
;; MSG SIZE  rcvd: 52

信息收集

[2024-06-17 10:33:46,496][NOTICE][       smartdns.c:640 ] smartdns starting...(Copyright (C) Nick Peng <pymumu@gmail.com>, build: 1.2024.05.09-1452)
[2024-06-17 10:33:46,497][ INFO][     dns_server.c:9013] bind ip [::]:53, type 0
[2024-06-17 10:33:46,497][ INFO][     dns_server.c:6404] ICMP ping is disabled, no ipv6 icmp check feature
[2024-06-17 10:33:46,497][ INFO][     dns_server.c:9330] IPV6 is not ready or speed check is disabled, disable IPV6 features
[2024-06-17 10:33:46,498][ INFO][     dns_client.c:1272] add server 1.1.1.1:53, type: udp
[2024-06-17 10:33:47,191][DEBUG][     dns_server.c:7155] recv query packet from 192.168.1.220, len = 36, type = 0
[2024-06-17 10:33:47,191][DEBUG][     dns_server.c:7171] request qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 36, id = 63584, tc = 0, rd = 1, ra = 0, rcode = 0
[2024-06-17 10:33:47,191][DEBUG][     dns_server.c:7196] query test5mx.scruel.com from 192.168.1.220, qtype: 1, id: 63584, query-num: 1
[2024-06-17 10:33:47,194][DEBUG][     dns_client.c:3855] send query to server 1.1.1.1:53
[2024-06-17 10:33:47,194][ INFO][     dns_client.c:4252] request: test5mx.scruel.com, qtype: 1, id: 40038, group: default
[2024-06-17 10:33:47,405][DEBUG][     dns_client.c:2609] recv udp packet from 1.1.1.1:53, len: 63, ttl: 52, latency: 27
[2024-06-17 10:33:47,405][DEBUG][     dns_client.c:1836] qdcount = 1, ancount = 1, nscount = 0, nrcount = 0, len = 63, id = 40038, tc = 0, rd = 1, ra = 1, rcode = 0, payloadsize = 1232
[2024-06-17 10:33:47,405][DEBUG][     dns_client.c:1848] domain: test5mx.scruel.com qtype: 1  qclass: 1
[2024-06-17 10:33:47,405][DEBUG][     dns_server.c:4644] query result from server 1.1.1.1:53, type: 0, domain: test5mx.scruel.com qtype: 1 rcode: 0, id: 63584
[2024-06-17 10:33:47,405][DEBUG][     dns_server.c:3865] domain: test5mx.scruel.com TTL: 300 IP: 1.1.1.1
[2024-06-17 10:33:47,405][ INFO][     dns_server.c:2613] result: test5mx.scruel.com, qtype: 1, rtt: -0.1 ms, 1.1.1.1
[2024-06-17 10:33:47,405][DEBUG][     dns_server.c:2336] reply test5mx.scruel.com qtype: 1, rcode: 0, reply: 1
[2024-06-17 10:33:47,405][DEBUG][     dns_server.c:1189] result: test5mx.scruel.com, rtt: -0.1 ms, 1.1.1.1
[2024-06-17 10:33:47,405][DEBUG][     dns_server.c:1666] cache test5mx.scruel.com qtype: 1 ttl: 600
[2024-06-17 10:33:47,405][ INFO][     dns_server.c:2391] result: test5mx.scruel.com, client: 192.168.1.220, qtype: 1, id: 63584, group: default, time: 214ms
[2024-06-17 10:33:47,405][DEBUG][     dns_client.c:1600] result: test5mx.scruel.com, qtype: 1, has-result: 1, id 40038
[2024-06-17 10:33:47,588][DEBUG][     dns_client.c:2609] recv udp packet from 1.1.1.1:53, len: 103, ttl: 52, latency: 211
[2024-06-17 10:34:02,282][DEBUG][     dns_server.c:7155] recv query packet from fe80::eb23:cfdf:83ae:3adf, len = 47, type = 0
[2024-06-17 10:34:02,282][DEBUG][     dns_server.c:7171] request qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 47, id = 24457, tc = 0, rd = 1, ra = 0, rcode = 0
[2024-06-17 10:34:02,282][DEBUG][     dns_server.c:7196] query test5m1.scruel.com from fe80::eb23:cfdf:83ae:3adf, qtype: 1, id: 24457, query-num: 1
[2024-06-17 10:34:02,282][DEBUG][     dns_client.c:3855] send query to server 1.1.1.1:53
[2024-06-17 10:34:02,282][ INFO][     dns_client.c:4252] request: test5m1.scruel.com, qtype: 1, id: 30921, group: default
[2024-06-17 10:34:02,315][DEBUG][     dns_server.c:7155] recv query packet from 192.168.1.220, len = 47, type = 0
[2024-06-17 10:34:02,315][DEBUG][     dns_server.c:7171] request qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 47, id = 24457, tc = 0, rd = 1, ra = 0, rcode = 0
[2024-06-17 10:34:02,315][DEBUG][     dns_server.c:7196] query test5m1.scruel.com from 192.168.1.220, qtype: 1, id: 24457, query-num: 2
[2024-06-17 10:34:02,453][DEBUG][     dns_client.c:2609] recv udp packet from 1.1.1.1:53, len: 107, ttl: 52, latency: 170
[2024-06-17 10:34:02,453][DEBUG][     dns_client.c:1836] qdcount = 1, ancount = 0, nscount = 1, nrcount = 0, len = 107, id = 30921, tc = 0, rd = 1, ra = 1, rcode = 3, payloadsize = 1232
[2024-06-17 10:34:02,453][DEBUG][     dns_client.c:1848] domain: test5m1.scruel.com qtype: 1  qclass: 1
[2024-06-17 10:34:02,453][DEBUG][     dns_server.c:4644] query result from server 1.1.1.1:53, type: 0, domain: test5m1.scruel.com qtype: 1 rcode: 3, id: 24457
[2024-06-17 10:34:02,453][DEBUG][     dns_server.c:4160] domain: test5m1.scruel.com, qtype: 1, SOA: mname: carol.ns.cloudflare.com, rname: dns.cloudflare.com, serial: -1950861521, refresh: 10000, retry: 2400, expire: 604800, minimum: 1800
[2024-06-17 10:34:02,453][ INFO][     dns_server.c:2610] result: test5m1.scruel.com, qtype: 1, SOA
[2024-06-17 10:34:02,453][DEBUG][     dns_server.c:2336] reply test5m1.scruel.com qtype: 1, rcode: 0, reply: 1
[2024-06-17 10:34:02,453][DEBUG][     dns_server.c:1219] result: test5m1.scruel.com, qtype: 1, return SOA
[2024-06-17 10:34:02,453][ INFO][     dns_server.c:1234] result: test5m1.scruel.com, qtype: 1, rtcode: 3, id: 24457
[2024-06-17 10:34:02,453][ INFO][     dns_server.c:2391] result: test5m1.scruel.com, client: fe80::eb23:cfdf:83ae:3adf, qtype: 1, id: 24457, group: default, time: 170ms
[2024-06-17 10:34:02,453][DEBUG][     dns_server.c:4449] domain: test5m1.scruel.com, qtype: 1, SOA: mname: carol.ns.cloudflare.com, rname: dns.cloudflare.com, serial: -1950861521, refresh: 10000, retry: 2400, expire: 604800, minimum: 1800
[2024-06-17 10:34:02,453][DEBUG][     dns_server.c:4449] domain: test5m1.scruel.com, qtype: 1, SOA: mname: carol.ns.cloudflare.com, rname: dns.cloudflare.com, serial: -1950861521, refresh: 10000, retry: 2400, expire: 604800, minimum: 1800
[2024-06-17 10:34:02,453][ INFO][     dns_server.c:4500] result: test5m1.scruel.com, client: 192.168.1.220, qtype: 1, id: 24457, group: default, time: 137ms
[2024-06-17 10:34:02,453][DEBUG][     dns_client.c:1600] result: test5m1.scruel.com, qtype: 1, has-result: 1, id 30921
[2024-06-17 10:34:03,631][DEBUG][     dns_server.c:7155] recv query packet from fe80::eb23:cfdf:83ae:3adf, len = 47, type = 0
[2024-06-17 10:34:03,631][DEBUG][     dns_server.c:7171] request qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 47, id = 21487, tc = 0, rd = 1, ra = 0, rcode = 0
[2024-06-17 10:34:03,631][DEBUG][     dns_server.c:7196] query test5m1.scruel.com from fe80::eb23:cfdf:83ae:3adf, qtype: 1, id: 21487, query-num: 1
[2024-06-17 10:34:03,631][DEBUG][     dns_server.c:4449] domain: test5m1.scruel.com, qtype: 1, SOA: mname: carol.ns.cloudflare.com, rname: dns.cloudflare.com, serial: -1950861521, refresh: 10000, retry: 2400, expire: 604800, minimum: 1800
[2024-06-17 10:34:03,631][ INFO][     dns_server.c:4500] result: test5m1.scruel.com, client: fe80::eb23:cfdf:83ae:3adf, qtype: 1, id: 21487, group: default, time: 0ms
[2024-06-17 10:34:10,203][DEBUG][     dns_server.c:7155] recv query packet from fe80::eb23:cfdf:83ae:3adf, len = 47, type = 0
[2024-06-17 10:34:10,203][DEBUG][     dns_server.c:7171] request qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 47, id = 62673, tc = 0, rd = 1, ra = 0, rcode = 0
[2024-06-17 10:34:10,203][DEBUG][     dns_server.c:7196] query test5m1.scruel.com from fe80::eb23:cfdf:83ae:3adf, qtype: 1, id: 62673, query-num: 1
[2024-06-17 10:34:10,203][DEBUG][     dns_server.c:4449] domain: test5m1.scruel.com, qtype: 1, SOA: mname: carol.ns.cloudflare.com, rname: dns.cloudflare.com, serial: -1950861521, refresh: 10000, retry: 2400, expire: 604800, minimum: 1800
[2024-06-17 10:34:10,204][ INFO][     dns_server.c:4500] result: test5m1.scruel.com, client: fe80::eb23:cfdf:83ae:3adf, qtype: 1, id: 62673, group: default, time: 0ms
[2024-06-17 10:34:48,903][DEBUG][     dns_server.c:7155] recv query packet from fe80::eb23:cfdf:83ae:3adf, len = 47, type = 0
[2024-06-17 10:34:48,903][DEBUG][     dns_server.c:7171] request qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 47, id = 19438, tc = 0, rd = 1, ra = 0, rcode = 0
[2024-06-17 10:34:48,903][DEBUG][     dns_server.c:7196] query test5m1.scruel.com from fe80::eb23:cfdf:83ae:3adf, qtype: 1, id: 19438, query-num: 1
[2024-06-17 10:34:48,903][DEBUG][     dns_server.c:4449] domain: test5m1.scruel.com, qtype: 1, SOA: mname: carol.ns.cloudflare.com, rname: dns.cloudflare.com, serial: -1950861521, refresh: 10000, retry: 2400, expire: 604800, minimum: 1800
[2024-06-17 10:34:48,903][ INFO][     dns_server.c:4500] result: test5m1.scruel.com, client: fe80::eb23:cfdf:83ae:3adf, qtype: 1, id: 19438, group: default, time: 0ms
[2024-06-17 10:34:50,261][DEBUG][     dns_server.c:7155] recv query packet from fe80::eb23:cfdf:83ae:3adf, len = 47, type = 0
[2024-06-17 10:34:50,261][DEBUG][     dns_server.c:7171] request qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 47, id = 19547, tc = 0, rd = 1, ra = 0, rcode = 0
[2024-06-17 10:34:50,261][DEBUG][     dns_server.c:7196] query test5m1.scruel.com from fe80::eb23:cfdf:83ae:3adf, qtype: 1, id: 19547, query-num: 1
[2024-06-17 10:34:50,261][DEBUG][     dns_server.c:4449] domain: test5m1.scruel.com, qtype: 1, SOA: mname: carol.ns.cloudflare.com, rname: dns.cloudflare.com, serial: -1950861521, refresh: 10000, retry: 2400, expire: 604800, minimum: 1800
[2024-06-17 10:34:50,261][ INFO][     dns_server.c:4500] result: test5m1.scruel.com, client: fe80::eb23:cfdf:83ae:3adf, qtype: 1, id: 19547, group: default, time: 0ms
[2024-06-17 10:35:14,040][DEBUG][     dns_server.c:7155] recv query packet from fe80::eb23:cfdf:83ae:3adf, len = 47, type = 0
[2024-06-17 10:35:14,040][DEBUG][     dns_server.c:7171] request qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 47, id = 12804, tc = 0, rd = 1, ra = 0, rcode = 0
[2024-06-17 10:35:14,040][DEBUG][     dns_server.c:7196] query test5m1.scruel.com from fe80::eb23:cfdf:83ae:3adf, qtype: 1, id: 12804, query-num: 1
[2024-06-17 10:35:14,040][DEBUG][     dns_server.c:4449] domain: test5m1.scruel.com, qtype: 1, SOA: mname: carol.ns.cloudflare.com, rname: dns.cloudflare.com, serial: -1950861521, refresh: 10000, retry: 2400, expire: 604800, minimum: 1800
PikuZheng commented 2 weeks ago

猜测是无记录被缓存。超过缓存ttl后应该能正常

pymumu commented 2 weeks ago

用最新版本代码看看。

scruel commented 2 weeks ago

@pymumu 容器用的已经是 latest 标签了

pymumu commented 2 weeks ago
;; AUTHORITY SECTION:
test5m1.scruel.com.     1484    IN      SOA     carol.ns.cloudflare.com. dns.cloudflare.com. 2344105775 10000 2400 604800 1800

从这个结果看,SOA就是1.1.1.1返回的,你dig查询的和smartdns查询是不是走了不同网络?

scruel commented 2 weeks ago

@pymumu 走的是同一网络

PikuZheng commented 2 weeks ago
localhost:~# kdig +tls test5m1.scruel.com @1.1.1.1
;; TLS session (TLS1.3)-(ECDHE-X25519)-(ECDSA-SECP256R1-SHA256)-(AES-256-GCM)
;; ->>HEADER<<- opcode: QUERY; status: NXDOMAIN; id: 45309
;; Flags: qr rd ra; QUERY: 1; ANSWER: 0; AUTHORITY: 1; ADDITIONAL: 1

;; EDNS PSEUDOSECTION:
;; Version: 0; flags: ; UDP size: 1232 B; ext-rcode: NOERROR
;; PADDING: 357 B

;; QUESTION SECTION:
;; test5m1.scruel.com.          IN      A

;; AUTHORITY SECTION:
scruel.com.             1800    IN      SOA     carol.ns.cloudflare.com. dns.cloudflare.com. 2344109697 10000 2400 604800 1800

;; Received 468 B
;; Time 2024-06-18 10:52:20 CST
;; From 1.1.1.1@853(TLS) in 350.7 ms

有结果才是错的吧(运营商污染?

scruel commented 2 weeks ago

@PikuZheng 这是我当时测试时创建的记录,现在已经删掉了,可以用自己的域名测试。

PikuZheng commented 2 weeks ago

昂 那应该就是我说的 SOA时产生了缓存 直到过期后重新查询才能有结果。腾讯云说“解析在全球生效时间是0 - 72小时”

scruel commented 2 weeks ago

昂 那应该就是我说的 SOA时产生了缓存 直到过期后重新查询才能有结果。腾讯云说“解析在全球生效时间是0 - 72小时”

不像是 cdn 的问题,我是 cf 的 cdn 直接 dig @1.1.1.1 是能拿到新建的结果的

PikuZheng commented 2 weeks ago

昂 那应该就是我说的 SOA时产生了缓存 直到过期后重新查询才能有结果。腾讯云说“解析在全球生效时间是0 - 72小时”

不像是 cdn 的问题,我是 cf 的 cdn 直接 dig @1.1.1.1 是能拿到新建的结果的

唉呀!从时间线上来看。你在18:33通过smartdns查询了这个域名,此时这个域名还不存在,1.1.1.1返回soa并且被smartdns缓存了。18:39用dig直接查询,域名存在且有正确结果。但此时通过smartdns查询,smartdns的缓存里是soa,就直接返回soa。重启后再查询是18:43,要么缓存过期了,要么没设持久缓存文件而导致缓存清空了。此时smartdns需要重新向1.1.1.1查询,域名存在且有正确结果

scruel commented 2 weeks ago

你在18:33通过smartdns查询了这个域名,此时这个域名还不存在,1.1.1.1返回soa并且被smartdns缓存了。18:39用dig直接查询,域名存在且有正确结果。

反了,18:39:13 是直接向 1.1.1.1 查询,域名已存在,而后 18:39:19 才向本地 smartdns 发起查询,只要 smartdns 做得是同样的查询,应该结果一致才对,这个域名是新建的,之前也没有存在过,不应该存在缓存。

PikuZheng commented 2 weeks ago

18:39向smartdns查询时,smartdns不会也不应该向上游发起查询。

scruel commented 2 weeks ago

18:39向smartdns查询时,smartdns不会也不应该向上游发起查询。

为啥,域名是新的,以前都不存在,不向上游查,难不成能自己造出结果么,没太明白

PikuZheng commented 2 weeks ago

上面说了,你在18:33通过smartdns查询了这个域名,此时这个域名还不存在,1.1.1.1返回soa并且被smartdns缓存了。这个SOA就是结果。 NXDOMAIN、SOA、CNAME之类的都是DNS记录,会被缓存。缓存里有,就不会向上游发起查询。

scruel commented 2 weeks ago

反了,18:39:13 是直接向 1.1.1.1 查询,域名已存在,而后 18:39:19 才向本地 smartdns 发起查询,只要 smartdns 做得是同样的查询,应该结果一致才对,这个域名是新建的,之前也没有存在过,不应该存在缓存。 1.1.1.1返回soa并且被smartdns缓存了

13 秒就已经存在于 1.1.1.1 了,19 秒向本地 smartdns 查询的时候,为啥还能不存在?dig @1.1.1.1 可不走 smartdns 啊,完全没关系的。19 秒才是第一次用 smartdns 做查询,此时缓存也不可能存在,要想得到结果,肯定只能向上游 1.1.1.1 发起查询。

PikuZheng commented 2 weeks ago

13 秒就已经存在于 1.1.1.1 了,19 秒向本地 smartdns 查询的时候,为啥还能不存在?dig @1.1.1.1 可不走 smartdns 啊,完全没关系的。19 秒才是第一次用 smartdns 做查询,此时缓存也不可能存在,要想得到结果,肯定只能向上游 1.1.1.1 发起查询。

那你上面日志怎么来得 没理解为啥你一直纠结18:39的事却无视18:33的事

scruel commented 2 weeks ago

那你上面日志怎么来得 没理解为啥你一直纠结18:39的事却无视18:33的事

哦你说日志啊,一直以为你说的是命令运行结果。但记得测试 smartdns 之前(33 之前),1.1.1.1 就已经能正确返回结果了,晚点再重新跑一边

scruel commented 3 days ago

未能复现问题