Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

配置了speed check mode后,不返回cname记录,无法与simple dns plus协同工作。 #1879

Open
ncluj opened this issue Dec 19, 2024 · 8 comments

Comments

@ncluj
Copy link

ncluj commented Dec 19, 2024

问题现象
结构简述:client->simple dns plus -> smartdns
需求背景:之前一直是用simple dns plus,主要图它的实时监控gui和cache。最近因为上游流量有审计,有内网终端可能请求了一些c2c域名被检测到,惹麻烦,想往上游走DoT,可sdp不支持,再试用了smartdns的速度优选功能,觉得很有效果,打算在sdp上游改为smartdns,smartdns开启speed check,上游走DoT。

运行环境
Win10 Ent
simple dns plus 9
smartdns 0.9
4. 涉及的配置(注意去除个人相关信息)
speed-check-mode ping,tcp:80,tcp:443
smartdns 侦听本地网卡 127.0.0.1:53
simple dns plus侦听本地IP 192.168.31.171:53,配置上游dns 127.0.0.1
重现步骤

  1. 不启用speedcheck
    1.1直接请求smartdns
> server 127.0.0.1
默认服务器:  localhost
Address:  127.0.0.1

> www.baidu.com
服务器:  localhost
Address:  127.0.0.1

非权威应答:
非权威应答:
名称:    www.a.shifen.com
Addresses:  240e:ff:e020:9ae:0:ff:b014:8e8b
          240e:ff:e020:966:0:ff:b042:f296
          183.2.172.42
Aliases:  www.baidu.com

1.2 请求simplednsplus

> server 192.168.31.171
默认服务器:  smartdns
Address:  192.168.31.171

> www.baidu.com
服务器:  smartdns
Address:  192.168.31.171

名称:    www.a.shifen.com
Addresses:  240e:ff:e020:966:0:ff:b042:f296
          240e:ff:e020:9ae:0:ff:b014:8e8b
Aliases:  www.baidu.com


正常返回。查看simplednsplus日志,正常通过smartdns返回

10:00:50   Request from 192.168.31.171 for A-record for www.baidu.com.lan
10:00:50   Sending request to 127.0.0.1 (forward server) for A-record for www.baidu.com.lan
10:00:50   Reply from 127.0.0.1 about A-record for www.baidu.com.lan:
10:00:50   -> Answer: SOA-record for <root> = a.root-servers.net [2024121802]
10:00:50   Sending reply to 192.168.31.171 about A-record for www.baidu.com.lan:
10:00:50   -> Header: Server Failure
10:00:50   Request from 192.168.31.171 for AAAA-record for www.baidu.com.lan
10:00:50   Sending request to 127.0.0.1 (forward server) for AAAA-record for www.baidu.com.lan
10:00:51   Reply from 127.0.0.1 about AAAA-record for www.baidu.com.lan:
10:00:51   -> Answer: SOA-record for <root> = a.root-servers.net [2024121802]
10:00:51   Sending reply to 192.168.31.171 about AAAA-record for www.baidu.com.lan:
10:00:51   -> Header: Server Failure
10:00:51   Request from 192.168.31.171 for A-record for www.baidu.com
10:00:51   Sending request to 127.0.0.1 (forward server) for A-record for www.baidu.com
10:00:51   Reply from 127.0.0.1 about A-record for www.baidu.com:
10:00:51   -> Answer: A-record for www.a.shifen.com = 183.2.172.42
10:00:51   Sending reply to 192.168.31.171 about A-record for www.baidu.com:
10:00:51   -> Header: Server Failure
10:00:51   Request from 192.168.31.171 for AAAA-record for www.baidu.com
10:00:51   Sending request to 127.0.0.1 (forward server) for AAAA-record for www.baidu.com
10:00:51   Reply from 127.0.0.1 about AAAA-record for www.baidu.com:
10:00:51   -> Answer: CNAME-record for www.baidu.com = www.a.shifen.com
10:00:51   -> Answer: AAAA-record for www.a.shifen.com = 240e:ff:e020:966:0:ff:b042:f296
10:00:51   -> Answer: AAAA-record for www.a.shifen.com = 240e:ff:e020:9ae:0:ff:b014:8e8b
10:00:51   Sending reply to 192.168.31.171 about AAAA-record for www.baidu.com:
10:00:51   -> Answer: CNAME-record for www.baidu.com = www.a.shifen.com
10:00:51   -> Answer: AAAA-record for www.a.shifen.com = 240e:ff:e020:966:0:ff:b042:f296
10:00:51   -> Answer: AAAA-record for www.a.shifen.com = 240e:ff:e020:9ae:0:ff:b014:8e8b

2.启用speed check mode
2.1 直接请求smartdns

> www.baidu.com
服务器:  localhost
Address:  127.0.0.1

非权威应答:
非权威应答:
名称:    www.a.shifen.com
Addresses:  240e:ff:e020:966:0:ff:b042:f296
          183.2.172.185

返回一条测速后的记录,注意,没有CName记录
2.2请求 simple dns plus

> server  192.168.31.171
默认服务器:  smartdns
Address:  192.168.31.171

> www.baidu.com
服务器:  smartdns
Address:  192.168.31.171

*** smartdns 找不到 www.baidu.com: Server failed

失败了。
调取simplednsplus日志


10:09:06   Request from 192.168.31.171 for A-record for www.baidu.com.lan
10:09:06   Sending request to 127.0.0.1 (forward server) for A-record for www.baidu.com.lan
10:09:07   Reply from 127.0.0.1 about A-record for www.baidu.com.lan:
10:09:07   -> Answer: SOA-record for <root> = a.root-servers.net [2024121802]
10:09:07   Sending reply to 192.168.31.171 about A-record for www.baidu.com.lan:
10:09:07   -> Header: Server Failure
10:09:07   Request from 192.168.31.171 for AAAA-record for www.baidu.com.lan
10:09:07   Sending request to 127.0.0.1 (forward server) for AAAA-record for www.baidu.com.lan
10:09:07   Reply from 127.0.0.1 about AAAA-record for www.baidu.com.lan:
10:09:07   -> Answer: SOA-record for <root> = a.root-servers.net [2024121802]
10:09:07   Sending reply to 192.168.31.171 about AAAA-record for www.baidu.com.lan:
10:09:07   -> Header: Server Failure
10:09:07   Request from 192.168.31.171 for A-record for www.baidu.com
10:09:07   Sending request to 127.0.0.1 (forward server) for A-record for www.baidu.com
10:09:07   Reply from 127.0.0.1 about A-record for www.baidu.com:
10:09:07   -> Answer: A-record for www.a.shifen.com = 183.2.172.42
10:09:07   Sending reply to 192.168.31.171 about A-record for www.baidu.com:
10:09:07   -> Header: Server Failure
10:09:07   Request from 192.168.31.171 for AAAA-record for www.baidu.com
10:09:07   Sending request to 127.0.0.1 (forward server) for AAAA-record for www.baidu.com
10:09:07   Reply from 127.0.0.1 about AAAA-record for www.baidu.com:
10:09:07   -> Answer: AAAA-record for www.a.shifen.com = 240e:ff:e020:966:0:ff:b042:f296
10:09:07   Sending reply to 192.168.31.171 about AAAA-record for www.baidu.com:
10:09:07   -> Header: Server Failure

如直接请求的一致,向127.0.0.1转发了请求,直接返回了 www.a.shifen.com 的A记录和AAAA记录,但是simplednsplus不认可,可能觉得跟www.baidu.com没关系,忽略不计了,返回了个Server Failure。

这是simplednsplus的问题,还是smartdns的问题。如果是simplednsplus的问题,smartdns有没有个选项,可以在优选测速后的ip后,还把cname记录给返回。

交叉测试:使用www.google.com域名测试,返回的是www.google.com的A记录,没问题。使用其他带cdn的域名测试,都是这个情况。

smartdns的日志供参考:


2024-12-19 10:06:56.652:INFO: Smart-DNS 🐋 0.9.0 🕙 Sun Oct 13 10:00:51 UTC 2024 starting
2024-12-19 10:06:56.654:INFO: loading configuration from: "./smartdns.conf"
2024-12-19 10:06:56.660:INFO: whoami 👉 smartdns
2024-12-19 10:06:56.671:INFO: num workers: 8
2024-12-19 10:06:56.674:INFO: upstream server: https://cloudflare-dns.com/dns-query [Group: []]
2024-12-19 10:06:56.677:INFO: upstream server: https://dns.alidns.com/dns-query [Group: default]
2024-12-19 10:06:56.677:INFO: upstream server: https://doh.pub/dns-query [Group: default]
2024-12-19 10:06:56.678:INFO: cache: size(32768)
2024-12-19 10:06:56.678:INFO: cache persist: NO
2024-12-19 10:06:56.679:INFO: domain prefetch: OFF
2024-12-19 10:06:56.679:INFO: speed check mode: ICMP, TCP:80, TCP:443
2024-12-19 10:06:56.686:WARN:smartdns::dns_client:118: bootstrap-dns must use ip addess, Domain("cloudflare-dns.com")
2024-12-19 10:06:56.686:WARN:smartdns::dns_client:137: not bootstrap-dns found, use system_conf instead.
2024-12-19 10:06:56.689:DEBUG:smartdns::server::net:65: binding UDP to 127.0.0.1:53
2024-12-19 10:06:56.697:INFO: listening for UDP on 127.0.0.1:53
2024-12-19 10:06:56.698:DEBUG:smartdns::server::net:65: binding UDP to [::]:53
2024-12-19 10:06:56.698:INFO: listening for UDP on [::]:53
2024-12-19 10:06:56.698:INFO:
2024-12-19 10:06:56.699:INFO:      _____                      _       _____  _   _  _____
2024-12-19 10:06:56.699:INFO:     / ____|                    | |     |  __ \| \ | |/ ____|
2024-12-19 10:06:56.699:INFO:    | (___  _ __ ___   __ _ _ __| |_    | |  | |  \| | (___
2024-12-19 10:06:56.700:INFO:     \___ \| '_ ` _ \ / _` | '__| __|   | |  | | . ` |\___ \
2024-12-19 10:06:56.700:INFO:     ____) | | | | | | (_| | |  | |_    | |__| | |\  |____) |
2024-12-19 10:06:56.700:INFO:    |_____/|_| |_| |_|\__,_|_|   \__|   |_____/|_| \_|_____/
2024-12-19 10:06:56.701:INFO:
2024-12-19 10:06:56.701:INFO: awaiting connections...
2024-12-19 10:06:56.701:INFO: server starting up
2024-12-19 10:07:01.404:DEBUG:smartdns::server::udp:45: received udp request from: 127.0.0.1:55506
2024-12-19 10:07:01.405:DEBUG:smartdns::app:366: request:237 src:udp://127.0.0.1#55506 type:QUERY dnssec:false QUERY:www.baidu.com.lan.:A:IN qflags:RD
2024-12-19 10:07:01.406:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com.lan. type: A via [Group: default]
2024-12-19 10:07:01.410:DEBUG:smartdns::dns_client::bootstrap:1330: lookup nameserver doh.pub A, [1.12.12.12, 120.53.53.53]
2024-12-19 10:07:01.414:DEBUG:smartdns::dns_client::bootstrap:1330: lookup nameserver dns.alidns.com A, [223.6.6.6, 223.5.5.5]
2024-12-19 10:07:01.562:DEBUG:smartdns::server::udp:45: received udp request from: 127.0.0.1:55508
2024-12-19 10:07:01.562:DEBUG:smartdns::app:366: request:238 src:udp://127.0.0.1#55508 type:QUERY dnssec:false QUERY:www.baidu.com.lan.:AAAA:IN qflags:RD
2024-12-19 10:07:01.564:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com.lan. type: AAAA via [Group: default]
2024-12-19 10:07:01.565:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com.lan. type: A via [Group: default]
2024-12-19 10:07:01.628:DEBUG:smartdns::server::udp:45: received udp request from: 127.0.0.1:55509
2024-12-19 10:07:01.629:DEBUG:smartdns::app:366: request:239 src:udp://127.0.0.1#55509 type:QUERY dnssec:false QUERY:www.baidu.com.:A:IN qflags:RD
2024-12-19 10:07:01.630:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com. type: A via [Group: default]
2024-12-19 10:07:01.872:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. ICMP ping [183.2.172.42, 183.2.172.185]
2024-12-19 10:07:01.890:DEBUG:smartdns::dns_mw_ns:477: The fastest ip of www.baidu.com. is 183.2.172.185, delay: 17.0652ms
2024-12-19 10:07:01.891:DEBUG:smartdns::server::udp:45: received udp request from: 127.0.0.1:55510
2024-12-19 10:07:01.891:DEBUG:smartdns::app:366: request:240 src:udp://127.0.0.1#55510 type:QUERY dnssec:false QUERY:www.baidu.com.:AAAA:IN qflags:RD
2024-12-19 10:07:01.892:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com. type: AAAA via [Group: default]
2024-12-19 10:07:01.893:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com. type: A via [Group: default]
2024-12-19 10:07:01.913:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. ICMP ping [183.2.172.185, 183.2.172.42]
2024-12-19 10:07:01.917:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. ICMP ping [183.2.172.42, 183.2.172.185]
2024-12-19 10:07:01.925:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. ICMP ping [240e:ff:e020:966:0:ff:b042:f296, 240e:ff:e020:9ae:0:ff:b014:8e8b]
2024-12-19 10:07:01.926:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. TCP:80 ping [240e:ff:e020:966:0:ff:b042:f296, 240e:ff:e020:9ae:0:ff:b014:8e8b]
2024-12-19 10:07:01.927:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. TCP:443 ping [240e:ff:e020:966:0:ff:b042:f296, 240e:ff:e020:9ae:0:ff:b014:8e8b]
2024-12-19 10:07:01.931:DEBUG:smartdns::dns_mw_ns:477: The fastest ip of www.baidu.com. is 183.2.172.185, delay: 17.4527ms
2024-12-19 10:09:05.625:DEBUG:smartdns::server::udp:45: received udp request from: 127.0.0.1:56472
2024-12-19 10:09:05.627:DEBUG:smartdns::app:366: request:241 src:udp://127.0.0.1#56472 type:QUERY dnssec:false QUERY:171.31.168.192.in-addr.arpa.:PTR:IN qflags:RD
2024-12-19 10:09:06.989:DEBUG:smartdns::server::udp:45: received udp request from: 127.0.0.1:65529
2024-12-19 10:09:06.990:DEBUG:smartdns::app:366: request:24674 src:udp://127.0.0.1#65529 type:QUERY dnssec:false QUERY:www.baidu.com.lan.:A:IN qflags:RD
2024-12-19 10:09:06.992:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com.lan. type: A via [Group: default]
2024-12-19 10:09:07.113:DEBUG:smartdns::server::udp:45: received udp request from: 127.0.0.1:61252
2024-12-19 10:09:07.113:DEBUG:smartdns::app:366: request:19840 src:udp://127.0.0.1#61252 type:QUERY dnssec:false QUERY:www.baidu.com.lan.:AAAA:IN qflags:RD
2024-12-19 10:09:07.115:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com.lan. type: AAAA via [Group: default]
2024-12-19 10:09:07.115:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com.lan. type: A via [Group: default]
2024-12-19 10:09:07.203:DEBUG:smartdns::server::udp:45: received udp request from: 127.0.0.1:52251
2024-12-19 10:09:07.203:DEBUG:smartdns::app:366: request:8155 src:udp://127.0.0.1#52251 type:QUERY dnssec:false QUERY:www.baidu.com.:A:IN qflags:RD
2024-12-19 10:09:07.205:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com. type: A via [Group: default]
2024-12-19 10:09:07.223:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. ICMP ping [183.2.172.42, 183.2.172.185]
2024-12-19 10:09:07.238:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. ICMP ping [183.2.172.185, 183.2.172.42]
2024-12-19 10:09:07.243:DEBUG:smartdns::dns_mw_ns:477: The fastest ip of www.baidu.com. is 183.2.172.42, delay: 18.3772ms
2024-12-19 10:09:07.244:DEBUG:smartdns::server::udp:45: received udp request from: 127.0.0.1:39780
2024-12-19 10:09:07.244:DEBUG:smartdns::app:366: request:63461 src:udp://127.0.0.1#39780 type:QUERY dnssec:false QUERY:www.baidu.com.:AAAA:IN qflags:RD
2024-12-19 10:09:07.245:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com. type: AAAA via [Group: default]
2024-12-19 10:09:07.246:DEBUG:smartdns::dns_mw_ns:97: query name: www.baidu.com. type: A via [Group: default]
2024-12-19 10:09:07.264:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. ICMP ping [240e:ff:e020:9ae:0:ff:b014:8e8b, 240e:ff:e020:966:0:ff:b042:f296]
2024-12-19 10:09:07.265:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. TCP:80 ping [240e:ff:e020:9ae:0:ff:b014:8e8b, 240e:ff:e020:966:0:ff:b042:f296]
2024-12-19 10:09:07.268:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. TCP:443 ping [240e:ff:e020:9ae:0:ff:b014:8e8b, 240e:ff:e020:966:0:ff:b042:f296]
2024-12-19 10:09:07.270:DEBUG:smartdns::dns_mw_ns:466: Speed test www.baidu.com. ICMP ping [183.2.172.42, 183.2.172.185]

信息收集

  1. 将/var/log/smrtdns.log日志作为附件上传(注意去除个人相关信息)。
  2. 如进程异常,请将coredump功能开启,上传coredump信息文件,同时上传配套的smartdns进程文件。
    在自定义界面,开启设置->自定义设置->生成coredump配置,重现问题后提交coredump文件
    coredump文件在/tmp目录下
@PikuZheng
Copy link
Contributor

尝试配置 force-no-CNAME yes

大致上看这应该是 simplednsplus 转发不规范。一个DNS转发器处理具有cname的双栈域名时应该向上游发起两次请求,第一次查询 www.baidu.com A。上游返回cname=www.a.shifen.com后,应使用 www.a.shifen.com AAAA发起第二次查询。

@ncluj
Copy link
Author

ncluj commented Dec 19, 2024

从simplednsplus日志,以及nslookup直接查询smartdns看,simplednsplus发起查询www.baidu.com的A记录,smartdns直接返回www.a.shifen.com的A记录,而不是返回cname(好像和您说的正好相反)。
如果不配置speedcheck,smartdns既返回cname=shifen.com,又返回shifen.com的A记录。是否smartdns的策略就是,测速后只返回速度最好的A记录,不返回cname。能否通过源码验证一下。然后,这样不返回cname是smartdns返回不规范,还是simplednsplus丢弃不规范。我也看不懂规范原文,麻烦您解读下看看。

我个人理解,simplednsplus请求 a.com的A记录,上游返回b.com的A记录(没有cname记录说明a.com=b.com),丢弃这个数据是可以理解的。好像有个说明是,防止dns污染防护吧。

对了。force-no-CNAME yes试过了,没用。

您可以直接在smartdns重现,配置了speedcheck后,请求www.baidu.com,直接返回shifen.com的A记录,没有cname.

@ncluj
Copy link
Author

ncluj commented Dec 19, 2024

图片
simplednsplus这段文档,好像说的是这个特性。我英文不好,劳烦您看下。

@PikuZheng
Copy link
Contributor

implednsplus发起查询www.baidu.com的A记录,smartdns直接返回www.a.shifen.com的A记录,而不是返回cname(好像和您说的正好相反)。

根据我的测试,smartdns 在配置了speed-check-mode ping时能够正确返回cname和a
image

在配置了 speed-check-mode none时也同时返回了cname和a
image

@PikuZheng
Copy link
Contributor

image
是这个软件吗?配置上游为smartdns 没问题啊

另外都windows了,为什么不用自带的dns server组件或者unbound(我自己在windows上是用unbound作为dns服务器的

@ncluj
Copy link
Author

ncluj commented Dec 19, 2024

观察到您是用linux dig命令测试,我也试了一下。结果却还是不返回cname 。截图如下:
图片
我精简了配置文件,完整的配置文件如下:


server-name smartdns
bind :53
bind [::]:53

speed-check-mode ping
log-level info

server https://cloudflare-dns.com/dns-query  -bootstrap-dns -exclude-default-group
server https://dns.alidns.com/dns-query
server https://doh.pub/dns-query

观察到您是使用的linux下的c版本,我尝试装个再测试一下。我用的是rust版本

Windows | smartdns-rs https://github.com/mokeyish/smartdns-rs | Rust版本SmartDNS

Rust版本没有单独的issue,只能贴到这儿。

@ncluj
Copy link
Author

ncluj commented Dec 19, 2024

image 是这个软件吗?配置上游为smartdns 没问题啊

另外都windows了,为什么不用自带的dns server组件或者unbound(我自己在windows上是用unbound作为dns服务器的

谢谢您的回复。一个我看您这返回了多个IP,您这没有启用speed check mode。我的问题只在启用了speed check mode出现。二个,您是否运行的是Rust版本的smartdns.毕竟Win下只能用这个版本。三个,题外话,我用simpledns一个是有个gui比较好观察实时日志和实时负荷,二个比较轻量好配置。
再次感谢您的测试与回复,能不能劳烦您用rust版本,开启speed check mode 再帮我重现一下,是否有这个情况。

@PikuZheng
Copy link
Contributor

PikuZheng commented Dec 19, 2024

rust归隔壁管 https://github.com/mokeyish/smartdns-rs/issues

观察到您是用linux dig命令测试,我也试了一下。

我用的是kdig,不是dig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants