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
8.49k stars 1.09k forks source link

测速模式和响应模式参数配置优先级问题 #1807

Closed giveup closed 2 months ago

giveup commented 3 months ago

问题现象
和#https://github.com/pymumu/smartdns/issues/1790 类似,例如对于测速,共有三处地方可配置。 全局 speed-check-mode none 端口 [-no-speed-check]:停用测速 域名规则 domain-rules /example.com/ -speed-check-mode none 在配置文档均有说明https://pymumu.github.io/smartdns/config/check-speed-mode/ 但是没有提到优先级。 我的理解是域名规则优先级最高。 使用的配置如下

全局 speed-check-mode none
端口 bind :54@lo  -no-speed-check
域名 domain-rules address /*.github.io/  speed-check-mode tcp:443,ping
root@AX6S:/etc/openclash# smartdns --cache-print  /etc/smartdns/smartdns.cache  | grep 'github.io'
domain: pymumu.github.io, qtype: 1, rcode: 0, ttl: 600, speed: -0.1ms, result: 185.199.108.153, 185.199.111.153, 185.199.109.153, 185.199.110.153
domain: pymumu.github.io, qtype: 65, rcode: 0, ttl: 600, speed: -0.1ms

从缓存结果来看都是-0.1,似乎测速并没有生效。 类似的还有响应模式等参数的配置优先级。

运行环境

  1. 固件型号 OpenWrt 23.05.4

  2. 运营商

  3. smartdns来源以及版本 smartdns 1.2024.v46.0.9

  4. 涉及的配置(注意去除个人相关信息)

重现步骤

  1. 上游DNS配置。

  2. 访问的域名。
    github.io

信息收集

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

建议开debug日志看看这个域名有没有命中规则

giveup commented 2 months ago

@PikuZheng 请问怎么看日志关键字

Sun Aug 25 23:29:50 2024 user.debug smartdns: query pymumu.github.io from 127.0.0.1, qtype: 1, id: 21188, query-num: 1
Sun Aug 25 23:29:50 2024 user.info smartdns: RULE-MATCH, type: 11, domain: pymumu.github.io, rule: github.io.
Sun Aug 25 23:29:50 2024 user.info smartdns: result: pymumu.github.io, client: 127.0.0.1, qtype: 1, id: 21188, group: oversea, time: 1ms
Sun Aug 25 23:29:50 2024 user.info smartdns: RULE-MATCH, type: 11, domain: pymumu.github.io, rule: github.io.
Sun Aug 25 23:29:50 2024 user.debug smartdns: send query to server 1.12.12.12:853
Sun Aug 25 23:29:50 2024 user.debug smartdns: send query to server 120.53.53.53:853
Sun Aug 25 23:29:50 2024 user.debug smartdns: send query to server 223.6.6.6:853
Sun Aug 25 23:29:50 2024 user.debug smartdns: send query to server 223.5.5.5:853
Sun Aug 25 23:29:50 2024 user.info smartdns: request: pymumu.github.io, qtype: 1, id: 63171, group: oversea
Sun Aug 25 23:29:50 2024 user.debug smartdns: recv query packet from 127.0.0.1, len = 34, type = 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: request qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 34, id = 49680, tc = 0, rd = 1, ra = 0, rcode = 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: query pymumu.github.io from 127.0.0.1, qtype: 28, id: 49680, query-num: 2
Sun Aug 25 23:29:50 2024 user.info smartdns: RULE-MATCH, type: 11, domain: pymumu.github.io, rule: github.io.
Sun Aug 25 23:29:50 2024 user.debug smartdns: reply pymumu.github.io qtype: 28, rcode: 0, reply: 1
Sun Aug 25 23:29:50 2024 user.info smartdns: result: pymumu.github.io, client: 127.0.0.1, qtype: 28, id: 49680, group: oversea, time: 0ms
Sun Aug 25 23:29:50 2024 user.debug smartdns: recv query packet from 127.0.0.1, len = 34, type = 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: request qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 34, id = 7127, tc = 0, rd = 1, ra = 0, rcode = 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: query pymumu.github.io from 127.0.0.1, qtype: 65, id: 7127, query-num: 2
Sun Aug 25 23:29:50 2024 user.info smartdns: RULE-MATCH, type: 11, domain: pymumu.github.io, rule: github.io.
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io, qtype: 65, SOA: mname: dns1.p05.nsone.net, rname: hostmaster.nsone.net, serial: 1647625169, refresh: 43200, retry: 7200, expire: 1209600, minimum: 3600
Sun Aug 25 23:29:50 2024 user.info smartdns: result: pymumu.github.io, client: 127.0.0.1, qtype: 65, id: 7127, group: oversea, time: 0ms
Sun Aug 25 23:29:50 2024 user.info smartdns: RULE-MATCH, type: 11, domain: pymumu.github.io, rule: github.io.
Sun Aug 25 23:29:50 2024 user.debug smartdns: send query to server 1.12.12.12:853
Sun Aug 25 23:29:50 2024 user.debug smartdns: send query to server 120.53.53.53:853
Sun Aug 25 23:29:50 2024 user.debug smartdns: send query to server 223.6.6.6:853
Sun Aug 25 23:29:50 2024 user.debug smartdns: send query to server 223.5.5.5:853
Sun Aug 25 23:29:50 2024 user.info smartdns: request: pymumu.github.io, qtype: 65, id: 45072, group: oversea
Sun Aug 25 23:29:50 2024 user.debug smartdns: recv tcp packet from 223.5.5.5, len = 164
Sun Aug 25 23:29:50 2024 user.debug smartdns: qdcount = 1, ancount = 4, nscount = 0, nrcount = 0, len = 162, id = 63171, tc = 0, rd = 1, ra = 0, rcode = 0, payloadsize = 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io qtype: 1  qclass: 1
Sun Aug 25 23:29:50 2024 user.debug smartdns: query result from server 223.5.5.5:853, type: 2, domain: pymumu.github.io qtype: 1 rcode: 0, id: 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io TTL: 1 IP: 185.199.109.153
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io TTL: 1 IP: 185.199.108.153
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io TTL: 1 IP: 185.199.110.153
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io TTL: 1 IP: 185.199.111.153
Sun Aug 25 23:29:50 2024 user.debug smartdns: recv tcp packet from 223.6.6.6, len = 164
Sun Aug 25 23:29:50 2024 user.debug smartdns: qdcount = 1, ancount = 4, nscount = 0, nrcount = 0, len = 162, id = 63171, tc = 0, rd = 1, ra = 0, rcode = 0, payloadsize = 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io qtype: 1  qclass: 1
Sun Aug 25 23:29:50 2024 user.debug smartdns: query result from server 223.6.6.6:853, type: 2, domain: pymumu.github.io qtype: 1 rcode: 0, id: 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io TTL: 1 IP: 185.199.109.153
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io TTL: 1 IP: 185.199.111.153
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io TTL: 1 IP: 185.199.108.153
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io TTL: 1 IP: 185.199.110.153
Sun Aug 25 23:29:50 2024 user.debug smartdns: recv tcp packet from 223.5.5.5, len = 132
Sun Aug 25 23:29:50 2024 user.debug smartdns: qdcount = 1, ancount = 0, nscount = 1, nrcount = 0, len = 130, id = 45072, tc = 0, rd = 1, ra = 0, rcode = 0, payloadsize = 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io qtype: 65  qclass: 1
Sun Aug 25 23:29:50 2024 user.debug smartdns: query result from server 223.5.5.5:853, type: 2, domain: pymumu.github.io qtype: 65 rcode: 0, id: 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io, qtype: 65, SOA: mname: ns-1622.awsdns-10.co.uk, rname: awsdns-hostmaster.amazon.com, serial: 1, refresh: 7200, retry: 900, expire: 1209600, minimum: 86400
Sun Aug 25 23:29:50 2024 user.debug smartdns: recv tcp packet from 223.6.6.6, len = 132
Sun Aug 25 23:29:50 2024 user.debug smartdns: qdcount = 1, ancount = 0, nscount = 1, nrcount = 0, len = 130, id = 45072, tc = 0, rd = 1, ra = 0, rcode = 0, payloadsize = 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io qtype: 65  qclass: 1
Sun Aug 25 23:29:50 2024 user.debug smartdns: query result from server 223.6.6.6:853, type: 2, domain: pymumu.github.io qtype: 65 rcode: 0, id: 0
Sun Aug 25 23:29:50 2024 user.debug smartdns: domain: pymumu.github.io, qtype: 65, SOA: mname: ns-1622.awsdns-10.co.uk, rname: awsdns-hostmaster.amazon.com, serial: 1, refresh: 7200, retry: 900, expire: 1209600, minimum: 86400
Sun Aug 25 23:29:50 2024 user.debug smartdns: query pymumu.github.io result is invalid, -4
Sun Aug 25 23:29:51 2024 user.debug smartdns: recv tcp packet from 1.12.12.12, len = 122
Sun Aug 25 23:29:51 2024 user.debug smartdns: opt type 8
Sun Aug 25 23:29:51 2024 user.debug smartdns: ECS: family:1, source_prefix:21, scope_prefix:24, len:3
Sun Aug 25 23:29:51 2024 user.debug smartdns: ecs-ip
Sun Aug 25 23:29:51 2024 user.debug smartdns: qdcount = 1, ancount = 4, nscount = 0, nrcount = 0, len = 120, id = 63171, tc = 0, rd = 1, ra = 1, rcode = 0, payloadsize = 1232
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io qtype: 1  qclass: 1
Sun Aug 25 23:29:51 2024 user.debug smartdns: query result from server 1.12.12.12:853, type: 2, domain: pymumu.github.io qtype: 1 rcode: 0, id: 0
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io TTL: 3600 IP: 185.199.108.153
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io TTL: 3600 IP: 185.199.111.153
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io TTL: 3600 IP: 185.199.109.153
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io TTL: 3600 IP: 185.199.110.153
Sun Aug 25 23:29:51 2024 user.debug smartdns: recv tcp packet from 120.53.53.53, len = 122
Sun Aug 25 23:29:51 2024 user.debug smartdns: opt type 8
Sun Aug 25 23:29:51 2024 user.debug smartdns: ECS: family:1, source_prefix:21, scope_prefix:24, len:3
Sun Aug 25 23:29:51 2024 user.debug smartdns: ecs-ip
Sun Aug 25 23:29:51 2024 user.debug smartdns: qdcount = 1, ancount = 4, nscount = 0, nrcount = 0, len = 120, id = 63171, tc = 0, rd = 1, ra = 1, rcode = 0, payloadsize = 1232
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io qtype: 1  qclass: 1
Sun Aug 25 23:29:51 2024 user.debug smartdns: query result from server 120.53.53.53:853, type: 2, domain: pymumu.github.io qtype: 1 rcode: 0, id: 0
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io TTL: 3600 IP: 185.199.109.153
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io TTL: 3600 IP: 185.199.110.153
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io TTL: 3600 IP: 185.199.108.153
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io TTL: 3600 IP: 185.199.111.153
Sun Aug 25 23:29:51 2024 user.debug smartdns: result: pymumu.github.io, qtype: 1, has-result: 1, id 63171
Sun Aug 25 23:29:51 2024 user.debug smartdns: select best ip address, pymumu.github.io
Sun Aug 25 23:29:51 2024 user.debug smartdns: possible result: pymumu.github.io, rcode: 0,  hitnum: 4, 185.199.108.153
Sun Aug 25 23:29:51 2024 user.debug smartdns: reply pymumu.github.io qtype: 1, rcode: 0, reply: 1
Sun Aug 25 23:29:51 2024 user.debug smartdns: result: pymumu.github.io, rtt: -0.1 ms, 185.199.108.153
Sun Aug 25 23:29:51 2024 user.info smartdns: result: pymumu.github.io, id: 0, index: 1, rtt: -0.1 ms, 185.199.108.153
Sun Aug 25 23:29:51 2024 user.info smartdns: result: pymumu.github.io, id: 0, index: 2, rtt: -0.1 ms, 185.199.111.153
Sun Aug 25 23:29:51 2024 user.info smartdns: result: pymumu.github.io, id: 0, index: 3, rtt: -0.1 ms, 185.199.109.153
Sun Aug 25 23:29:51 2024 user.info smartdns: result: pymumu.github.io, id: 0, index: 4, rtt: -0.1 ms, 185.199.110.153
Sun Aug 25 23:29:51 2024 user.debug smartdns: cache pymumu.github.io qtype: 1 ttl: 600
Sun Aug 25 23:29:51 2024 user.debug smartdns: recv tcp packet from 1.12.12.12, len = 145
Sun Aug 25 23:29:51 2024 user.debug smartdns: opt type 8
Sun Aug 25 23:29:51 2024 user.debug smartdns: ECS: family:1, source_prefix:21, scope_prefix:24, len:3
Sun Aug 25 23:29:51 2024 user.debug smartdns: ecs-ip
Sun Aug 25 23:29:51 2024 user.debug smartdns: qdcount = 1, ancount = 0, nscount = 1, nrcount = 0, len = 143, id = 45072, tc = 0, rd = 1, ra = 1, rcode = 0, payloadsize = 1232
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io qtype: 65  qclass: 1
Sun Aug 25 23:29:51 2024 user.debug smartdns: query result from server 1.12.12.12:853, type: 2, domain: pymumu.github.io qtype: 65 rcode: 0, id: 0
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io, qtype: 65, SOA: mname: ns-1622.awsdns-10.co.uk, rname: awsdns-hostmaster.amazon.com, serial: 1, refresh: 7200, retry: 900, expire: 1209600, minimum: 86400
Sun Aug 25 23:29:51 2024 user.debug smartdns: query pymumu.github.io result is invalid, -4
Sun Aug 25 23:29:51 2024 user.debug smartdns: recv tcp packet from 120.53.53.53, len = 145
Sun Aug 25 23:29:51 2024 user.debug smartdns: opt type 8
Sun Aug 25 23:29:51 2024 user.debug smartdns: ECS: family:1, source_prefix:21, scope_prefix:24, len:3
Sun Aug 25 23:29:51 2024 user.debug smartdns: ecs-ip
Sun Aug 25 23:29:51 2024 user.debug smartdns: qdcount = 1, ancount = 0, nscount = 1, nrcount = 0, len = 143, id = 45072, tc = 0, rd = 1, ra = 1, rcode = 0, payloadsize = 1232
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io qtype: 65  qclass: 1
Sun Aug 25 23:29:51 2024 user.debug smartdns: query result from server 120.53.53.53:853, type: 2, domain: pymumu.github.io qtype: 65 rcode: 0, id: 0
Sun Aug 25 23:29:51 2024 user.debug smartdns: domain: pymumu.github.io, qtype: 65, SOA: mname: ns-1622.awsdns-10.co.uk, rname: awsdns-hostmaster.amazon.com, serial: 1, refresh: 7200, retry: 900, expire: 1209600, minimum: 86400
Sun Aug 25 23:29:51 2024 user.debug smartdns: query pymumu.github.io result is invalid, -4
Sun Aug 25 23:29:51 2024 user.debug smartdns: result: pymumu.github.io, qtype: 65, has-result: 1, id 45072
Sun Aug 25 23:29:51 2024 user.debug smartdns: reply pymumu.github.io qtype: 65, rcode: 0, reply: 1
Sun Aug 25 23:29:51 2024 user.debug smartdns: result: pymumu.github.io, qtype: 65, return SOA
Sun Aug 25 23:29:51 2024 user.debug smartdns: cache pymumu.github.io qtype: 65 ttl: 600
Sun Aug 25 23:29:51 2024 user.debug smartdns: recv query packet from 127.0.0.1, len = 43, type = 0
PikuZheng commented 2 months ago

Sun Aug 25 23:29:50 2024 user.info smartdns: RULE-MATCH, type: 11, domain: pymumu.github.io, rule: github.io. Sun Aug 25 23:29:50 2024 user.info smartdns: result: pymumu.github.io, client: 127.0.0.1, qtype: 1, id: 21188, group: oversea, time: 1ms

单看这个 貌似只设置了 namerserver /github.io/oversea,没有针对这个域名设置测速规则

giveup commented 2 months ago
speed-check-mode none
bind :54@br-lan  -no-speed-check -no-dualstack-selection -force-aaaa-soa -group oversea
conf-file /etc/smartdns/custom.conf

custom.conf如下

serve-expired-ttl 604800
domain-rules /*.github.io/  speed-check-mode tcp:443,ping -response-mode fastest-ip

请问这样算正确设置吗?@PikuZheng

PikuZheng commented 2 months ago

serve-expired-ttl 604800\ndomain-rules /*.github.io/ speed-check-mode tcp:443,ping -response-mode fastest-ip

语法错

giveup commented 2 months ago

@PikuZheng 请问正确的语法是什么,我已经仔细查看说明文档配置,但是可能理解有误。 想要达到的效果是,对于*.github.io域名,按照tcp 443端口进行测速,模式为最快IP。同时全局模式和第二端口关闭测速。

PikuZheng commented 2 months ago

(用手机回的 打字比较慢

speed-check-mode none
domain-rules /*.github.io/ -nameserver oversea -speed-check-mode tcp:443 -response-mode fastest-ip
giveup commented 2 months ago

@PikuZheng 需要加上-nameserver oversea参数吗? 我是基于端口分流的,下游客户端会把github.io会被转发给54端口,54端口已经设置为oversea组, oversea组配置如下

server-tls 223.5.5.5  -group oversea -exclude-default-group -subnet ecs-ip
server-tls 223.6.6.6  -group oversea -exclude-default-group -subnet ecs-ip
server-tls 1.12.12.12  -group oversea -exclude-default-group -subnet ecs-ip
server-tls 120.53.53.53  -group oversea -exclude-default-group -subnet ecs-ip

我看配置文档的说明

nameserver | 指定域名使用 server 组解析 | 无 | nameserver /domain/[group\|-], group 为组名,- 表示忽略此规则,配套 server 中的 -group 参数使用 | nameserver /www.example.com/office

这个是把指定域名使用指定的组,但是我已经按端口分流,应该不需要再按域名分流。

PikuZheng commented 2 months ago

但是我已经按端口分流,应该不需要再按域名分流。

正确的,不用再加了

giveup commented 2 months ago

@PikuZheng 所以我这配置就是正确的吗?那日志看不出来有测速的地方可能是什么问题呢?

PikuZheng commented 2 months ago

custom.conf如下

serve-expired-ttl 604800
domain-rules /*.github.io/  speed-check-mode tcp:443,ping -response-mode fastest-ip

请问这样算正确设置吗?@PikuZheng

你这个少减号(如果不是复制到github少了的话)

speed-check-mode none
bind :54@br-lan  -no-speed-check -no-dualstack-selection -force-aaaa-soa -group oversea
conf-file /etc/smartdns/custom.conf

此处不应有 -no-speed-check ,这个会导致所有测速规则跳过

giveup commented 2 months ago

@PikuZheng 也就是优先级上,全局>端口>大于Domain rule。 之所以使用domain rule的方式来配置是因为只有少数域名是频繁访问的,开启测速效果可能会更好,如果整个端口都开启测速,可能会导致dns查询需要较长时间才能返回结果。

PikuZheng commented 2 months ago

也就是优先级上,全局>端口>大于Domain rule。

反了,全局 < domain rule < -no-speed-check 全局和domain rule都是用来选择一种测速方法 -no-speed-check是强制不测速,而不是选择一种测速方法