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

反向域名集合缓存咨询 #1618

Open
lonecale opened this issue Jan 9, 2024 · 11 comments
Open

反向域名集合缓存咨询 #1618

lonecale opened this issue Jan 9, 2024 · 11 comments

Comments

@lonecale
Copy link

lonecale commented Jan 9, 2024

需求简述:
我计划将 SmartDNS 用作某些特定域名的预加载服务。我的目标是让 SmartDNS 仅针对一个特定的域名列表进行操作,并且只对这些域名进行缓存处理。对于不在这个列表中的任何域名,SmartDNS 不进行缓存。

具体应用背景:
我想将 SmartDNS 配置成仅对我指定的某些域名进行解析和缓存,而不是对所有通过它解析的域名都进行缓存。这是为了优化特定域名。

配置方案细节:
bind:默认不禁用缓存
创建一个名为 test 的域名集合,并通过文件 /etc/smartdns/domain-set/test.txt 定义这个集合。
配置规则,以便 test 集合内的域名通过我指定的上游服务器(例如 test 服务器)进行解析。

domain-set -name test -file '/etc/smartdns/domain-set/test.txt'
domain-rules /domain-set:test / -nameserver test

我想请教,是否有可能通过上述配置进行修改实现只对 test 域名集合中的域名进行缓存,而不缓存通过 SmartDNS 解析的其他所有域名?在不使用第二DNS服务器状况下

@PikuZheng
Copy link
Contributor

最新代码的group功能好像可以实现,但是配置文件要怎么写我还没有搞清楚。可以先参考这个

@lonecale
Copy link
Author

最新代码的group功能好像可以实现,但是配置文件要怎么写我还没有搞清楚。可以先参考这个

客户端规则好像只能针对指定的客户端,但是看了下好像也无法实现反向判断,并且在我的环境smartdns是局域网设备唯一DNS服务器,我希望的是所有设备都是这样。不是单一的

@pymumu
Copy link
Owner

pymumu commented Jan 10, 2024

最新代码增加了相关的能力

domain-set -name test -file '/etc/smartdns/domain-set/test.txt'
domain-rules /./ -no-cache

group-begin test
group-match -domain domain-set:test
group-end

如果是老代码
可以通过设置TTL超时时间来实现类似的效果

rr-ttl 1
rr-ttl-max 1
domain-set -name test -file '/etc/smartdns/domain-set/test.txt'
domain-rules /domain-set:test / -nameserver test -rr-ttl-min 600

@lonecale
Copy link
Author

domain-set -name test -file '/etc/smartdns/domain-set/test.txt'
domain-rules /domain-set:test / -nameserver test -rr-ttl-min 600

感谢
那像下面的配置应该都可以实现 只有test域名预加载缓存非test 不缓存

老代码

serve-expired no
prefetch-domain yes
cache-persist yes
cache-size 20000
cache-checkpoint-time 3600
rr-ttl 1
rr-ttl-max 1
domain-set -name test -file '/etc/smartdns/domain-set/test.txt'
domain-rules /domain-set:test / -nameserver test -rr-ttl-min 600

新代码

serve-expired no
prefetch-domain yes
cache-persist yes
cache-size 20000
cache-checkpoint-time 3600
domain-set -name test -file '/etc/smartdns/domain-set/test.txt'
domain-rules /./ -no-cache

group-begin test
group-match -domain domain-set:test
group-end

@lonecale
Copy link
Author

lonecale commented Jan 13, 2024

最新代码增加了相关的能力

domain-set -name test -file '/etc/smartdns/domain-set/test.txt'
domain-rules /./ -no-cache

group-begin test
group-match -domain domain-set:test
group-end

如果是老代码 可以通过设置TTL超时时间来实现类似的效果

rr-ttl 1
rr-ttl-max 1
domain-set -name test -file '/etc/smartdns/domain-set/test.txt'
domain-rules /domain-set:test / -nameserver test -rr-ttl-min 600

在比较最新版本的SmartDNS和之前的Release 43版本时,我发现了一个差异。在最新版本中,即使在接收到响应代码为0的情况下(没有有效的返回),系统仍会尝试重新发送请求。而在Release 43版本中,这种情况不会引发重试。这一点尤其显著,因为当上游DNS针对一个特定域名进行拦截并返回响应代码0时,按照正常逻辑,系统不应该进行重试。不太清楚这是什么情况

版本号:1.2023.v43.0.78
[2024-01-14 00:33:16,624][DEBUG][     dns_client.c:1799] qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 44, id = 14312, tc = 0, rd = 1, ra = 1, rcode = 0, payloadsize = 1200
[2024-01-14 00:33:16,624][DEBUG][     dns_client.c:1811] domain: www.youtube.com qtype: 28  qclass: 1
[2024-01-14 00:33:16,624][DEBUG][     dns_server.c:4173] query result from server 127.0.0.1:5353, type: 0, domain: www.youtube.com qtype: 28 rcode: 0, id: 44195
[2024-01-14 00:33:16,624][DEBUG][     dns_server.c:3749] no result, www.youtube.com qtype: 28, rcode: 0, id: 14312, retry
[2024-01-14 00:33:17,123][DEBUG][     dns_client.c:4449] retry query www.youtube.com, type: 28, id: 14312
[2024-01-14 00:33:17,123][DEBUG][     dns_client.c:3775] send query to server 127.0.0.1:5353
[2024-01-14 00:33:17,124][DEBUG][     dns_client.c:2531] recv udp packet from 127.0.0.1, len: 44, ttl: 64, latency: 0
[2024-01-14 00:33:17,124][DEBUG][     dns_client.c:1799] qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 44, id = 14312, tc = 0, rd = 1, ra = 1, rcode = 0, payloadsize = 1200
[2024-01-14 00:33:17,124][DEBUG][     dns_client.c:1811] domain: www.youtube.com qtype: 28  qclass: 1
[2024-01-14 00:33:17,124][DEBUG][     dns_server.c:4173] query result from server 127.0.0.1:5353, type: 0, domain: www.youtube.com qtype: 28 rcode: 0, id: 44195
[2024-01-14 00:33:17,124][DEBUG][     dns_server.c:3749] no result, www.youtube.com qtype: 28, rcode: 0, id: 14312, retry
[2024-01-14 00:33:17,723][DEBUG][     dns_client.c:4449] retry query www.youtube.com, type: 28, id: 14312
[2024-01-14 00:33:17,723][DEBUG][     dns_client.c:3775] send query to server 127.0.0.1:5353
[2024-01-14 00:33:17,724][DEBUG][     dns_client.c:2531] recv udp packet from 127.0.0.1, len: 44, ttl: 64, latency: 0
[2024-01-14 00:33:17,724][DEBUG][     dns_client.c:1799] qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 44, id = 14312, tc = 0, rd = 1, ra = 1, rcode = 0, payloadsize = 1200
[2024-01-14 00:33:17,724][DEBUG][     dns_client.c:1811] domain: www.youtube.com qtype: 28  qclass: 1
[2024-01-14 00:33:17,724][DEBUG][     dns_server.c:4173] query result from server 127.0.0.1:5353, type: 0, domain: www.youtube.com qtype: 28 rcode: 0, id: 44195
[2024-01-14 00:33:17,724][DEBUG][     dns_server.c:3749] no result, www.youtube.com qtype: 28, rcode: 0, id: 14312, retry
[2024-01-14 00:33:18,107][DEBUG][     dns_server.c:6506] recv query packet from 127.0.0.1, len = 33, type = 0
[2024-01-14 00:33:18,107][DEBUG][     dns_server.c:6518] request qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 33, id = 34726, tc = 0, rd = 1, ra = 0, rcode = 0
[2024-01-14 00:33:18,107][DEBUG][     dns_server.c:6542] query www.youtube.com from 127.0.0.1, qtype: 28, id: 34726, query-num: 2
[2024-01-14 00:33:18,323][DEBUG][     dns_client.c:4446] retry query www.youtube.com, type: 28, id: 14312 failed
[2024-01-14 00:33:18,323][DEBUG][     dns_client.c:1563] result: www.youtube.com, qtype: 28, has-result: 0, id 14312
[2024-01-14 00:33:18,323][ INFO][     dns_server.c:2455] result: www.youtube.com, qtype: 28, rtt: -0.1 ms, 0000:0000:0000:0000:0000:0000:0000:0000
[2024-01-14 00:33:18,323][DEBUG][     dns_server.c:2174] reply www.youtube.com qtype: 28, rcode: 0, reply: 1
[2024-01-14 00:33:18,323][ INFO][     dns_server.c:2229] result: www.youtube.com, client: 127.0.0.1, qtype: 28, id: 44195, group: default, time: 2288ms
[2024-01-14 00:33:18,323][ INFO][     dns_server.c:4053] result: www.youtube.com, client: 127.0.0.1, qtype: 28, id: 34726, group: default, time: 217ms

版本号:Release43-1
[2024-01-14 01:02:41,201][ INFO][     dns_server.c:4537] query server youtube.com from 127.0.0.1, qtype = 28
[2024-01-14 01:02:41,201][DEBUG][     dns_client.c:535 ] send query to group default
[2024-01-14 01:02:41,201][DEBUG][     dns_client.c:2910] send query to server 127.0.0.1
[2024-01-14 01:02:41,202][ INFO][     dns_client.c:3206] send request youtube.com, qtype 28, id 4
[2024-01-14 01:02:41,202][DEBUG][     dns_client.c:2021] recv udp packet from 127.0.0.1, len: 40, ttl: 64
[2024-01-14 01:02:41,202][DEBUG][     dns_client.c:1613] qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 40, id = 4, tc = 0, rd = 1, ra = 1, rcode = 0, payloadsize = 1200
[2024-01-14 01:02:41,202][DEBUG][     dns_client.c:1624] domain: youtube.com qtype: 28  qclass: 1
[2024-01-14 01:02:41,202][DEBUG][     dns_server.c:3086] query result from server 127.0.0.1: 5353, type: 0
[2024-01-14 01:02:41,202][DEBUG][     dns_client.c:1403] result: youtube.com, qtype: 28, hasresult: 1, id 4
[2024-01-14 01:02:41,202][DEBUG][     dns_server.c:1538] reply youtube.com qtype: 28, rcode: 0, reply: 1
[2024-01-14 01:02:41,202][DEBUG][     dns_server.c:1063] cache youtube.com qtype: 28 ttl: 0


@pymumu
Copy link
Owner

pymumu commented Jan 14, 2024

RCODE=0,且没有任何结果的情况,在某些上游查询会出现此问题,所以增加重试避免没有结果。

不清楚你的场景是什么。

@lonecale
Copy link
Author

lonecale commented Jan 14, 2024

RCODE=0,且没有任何结果的情况,在某些上游查询会出现此问题,所以增加重试避免没有结果。

不清楚你的场景是什么。

这个情况易出现,在双栈环境当中访问一个域名并且该域名没有IPV6的时候,大多数DNS都是这样返回,RCODE=0,且没有有效返回。重试很容易增加延迟,降低体验,哪怕配置双栈优选也是前提IPV6解析出来。

@pymumu
Copy link
Owner

pymumu commented Jan 14, 2024

按照协议,如果没有IPV6,会有一条SOA记录的。不会返回只有question的记录。

如果返回了只包含question,而没有answer记录,这条记录是会被标记为truncated的。属于无效结果,协议上是要求重新用TCP之类的协议查询的。

@pymumu
Copy link
Owner

pymumu commented Jan 14, 2024

想了一下,可以做一下细化判断,如果确认是truncated记录才重试,否则只是没有结果的记录,但非truncated,认为结果OK。

最新代码改了下,验证下看看吧。

@lonecale
Copy link
Author

想了一下,可以做一下细化判断,如果确认是truncated记录才重试,否则只是没有结果的记录,但非truncated,认为结果OK。

最新代码改了下,验证下看看吧。

看下面日志 最新代码在rcode 0下没有answer记录 是正常了


[2024-01-14 22:32:42,895][DEBUG][     dns_server.c:6542] query www.youtube.com from 127.0.0.1, qtype: 28, id: 37801, query-num: 2
[2024-01-14 22:32:42,895][DEBUG][     dns_client.c:3780] send query to server 127.0.0.1:5353
[2024-01-14 22:32:42,895][ INFO][     dns_client.c:4171] request: www.youtube.com, qtype: 28, id: 40680, group: default
[2024-01-14 22:32:42,896][DEBUG][     dns_client.c:2536] recv udp packet from 127.0.0.1, len: 44, ttl: 64, latency: 1
[2024-01-14 22:32:42,896][DEBUG][     dns_client.c:1800] qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 44, id = 40680, tc = 0, rd = 1, ra = 1, rcode = 0, payloadsize = 1200
[2024-01-14 22:32:42,896][DEBUG][     dns_client.c:1812] domain: www.youtube.com qtype: 28 qclass: 1
[2024-01-14 22:32:42,896][DEBUG][     dns_server.c:4173] query result from server 127.0.0.1:5353, type: 0, domain: www.youtube.com qtype: 28 rcode: 0, id: 37801
[2024-01-14 22:32:42,896][DEBUG][     dns_client.c:1564] result: www.youtube.com, qtype: 28, has-result: 1, id 40680
[2024-01-14 22:32:42,896][ INFO][     dns_server.c:2455] result: www.youtube.com, qtype: 28, rtt: -0.1 ms, 0000:0000:0000:0000:0000:0000:0000:0000
[2024-01-14 22:32:42,896][DEBUG][     dns_server.c:2174] reply www.youtube.com qtype: 28, rcode: 0, reply: 1
[2024-01-14 22:32:42,896][ INFO][     dns_server.c:2229] result: www.youtube.com, client: 127.0.0.1, qtype: 28, id: 37801, group: default, time: 1ms

测试其他的同样情况时候好像还是会重试,例如rcode:5的部分响应返回,正常rcode 5 不是直接拒绝吗?

[2024-01-14 22:45:23,548][DEBUG][     dns_server.c:6542] query adguard-dns.io from 127.0.0.1, qtype: 28, id: 43059, query-num: 2
[2024-01-14 22:45:23,548][DEBUG][     dns_client.c:3780] send query to server 127.0.0.1:5353
[2024-01-14 22:45:23,548][ INFO][     dns_client.c:4171] request: adguard-dns.io, qtype: 28, id: 17406, group: default
[2024-01-14 22:45:23,548][DEBUG][     dns_client.c:2536] recv udp packet from 127.0.0.1, len: 43, ttl: 64, latency: 1
[2024-01-14 22:45:23,548][DEBUG][     dns_client.c:1800] qdcount = 1, ancount = 0, nscount = 0, nrcount= 0, len = 43, id = 17406, tc = 0, rd = 1, ra = 1, rcode = 5, payloadsize = 1200
[2024-01-14 22:45:23,548][DEBUG][ dns_client.c:1812] domain: adguard-dns.io qtype: 28 qclass: 1
[2024-01-14 22:45:23,548][DEBUG][ dns_server.c:4173] query result from server 127.0.0.1:5353, type: 0, domain:adguard-dns.io qtype: 28 rcode: 5, id: 43059
[2024-01-14 22:45:23,548][DEBUG][ dns_server.c:3661] inquery failed, adguard-dns.io, rcode = 5, id = 17406
[2024-01-14 22:45:24,049][DEBUG][ dns_client.c:4052] retry query adguard-dns.io, type: 28, id: 17406
[2024-01-14 22:45:24,049][DEBUG][ dns_client.c:3780] send query to server 127.0.0.1:5353
[2024-01-14 22:45:24,049][DEBUG][ dns_client.c:2536] recv udp packet from 127.0.0.1, len: 43, ttl: 64, latency: 1
[2024-01-14 22:45:24,049][DEBUG][ dns_client.c:1800] qdcount = 1, ancount = 0, nscount = 0, nrcount = 0, len = 43, id = 17406, tc = 0, rd = 1, ra = 1, rcode = 5, payloadsize = 1200

@lonecale
Copy link
Author

lonecale commented Jan 14, 2024

最新代码的group功能好像可以实现,但是配置文件要怎么写我还没有搞清楚。可以先参考这个

发现新版本有个更简单的方式实现 先在服务端bind 配置直接no-cache

domain-set -name test -file '/etc/smartdns/domain-set/test.txt'
domain-rules /domain-set:test/ -enable-cache

然后针对域名集合开启缓存就可以了

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

3 participants