config: add cache, cname, dualstack guild

This commit is contained in:
Nick Peng
2023-03-11 17:52:57 +08:00
parent 55966e5b3f
commit 8bf1108503
6 changed files with 179 additions and 2 deletions

103
docs/config/cache.md Normal file
View File

@@ -0,0 +1,103 @@
---
hide:
- toc
---
# 缓存
SmartDNS提供了缓存能力开启缓存的情况下能提供更好的DNS查询请求smartdns提供的过期缓存功能会将体验更进一步提升。
## 缓存配置
SmartDNS可以通过`cache-size`配置缓存的条数,同时也可以通过`cache-persist`来配置是否持久化缓存,也可以通过`cache-file`来指定缓存文件存储路径
```shell
cache-size 32768
cache-persist yes
cache-file /path/to/cache/file
```
注意:
1. smartdns默认自动根据磁盘空间是否启用缓存。
1. 缓存文件只有在进程正常退出的时候才会保存供下次使用。
## 缓存预获取
Smartdns可以设置缓存预获取避免缓存超时配置预先获取后smartdns将在域名超时前的5s内重新进行域名查询。并对域名的热度进行排序。
```shell
prefetch-domain yes
```
注意:
1. 此功能将会导致smaratdns消耗更多的CPU。
## 过期缓存
过期缓存也要乐观缓存其功能指定是当DNS域名的TTL到0时其结果仍然存储在缓存中等下次查询时仍然将缓存的结果返回给客户端避免客户端等待。乐观缓存的前提时DNS的对应的IP地址不会频繁变化。
具体乐观缓存的原理可以参考(RFC 8767) (https://www.rfc-editor.org/rfc/rfc8767)
smartdns过期缓存处理流程
```mermaid
%%{init: {'theme':'forest'}}%%
sequenceDiagram
autonumber
participant client as 客户端
participant smartdns as SmartDNS
participant Server as 上游DNS服务器
client->>smartdns: DNS查询
alt 域名不在缓存中
smartdns->>+Server: 上游查询DNS
Server-->>-smartdns: 返回查询结果
smartdns->smartdns: 测速,并缓存结果
smartdns->client: 返回结果
else 域名在过期缓存中
rect rgb(160, 250, 140)
smartdns->smartdns: 域名在缓存中,且已经过期。
smartdns->client: 返回结果过期的域名结果TTL为3
smartdns->>+Server: 上游查询DNS
Server->-smartdns: 返回查询结果
smartdns->smartdns: 测速,并缓存结果
client->smartdns: 3s后客户端再次查询获取最佳结果。
end
end
```
## 配置步骤
1. 开启过期缓存
```shell
serve-expired yes
```
1. 配置过期缓存超时时间
此时间表示过期缓存多长时间未访问,则从缓存中释放。
```shell
serve-expired-ttl 259200
```
1. 配置过期缓存响应TTL
此时间表示当缓存中域名TTL超时时返回给客户端的TTL时间让客户端在下列TTL时间后再次查询。
```shell
serve-expired-reply-ttl 3
```
1. 过期缓存预获取时间
此时间表示过期缓存在多长时间未访问主动进行预先获取以避免IP无效开启过期缓存后prefetch的功能将和未开启不同。
```shell
prefetch-domain yes
serve-expired-prefetch-time 21600
```

18
docs/config/cname.md Normal file
View File

@@ -0,0 +1,18 @@
---
hide:
- toc
---
# cname别名查询
某些情况下需要将a域名的查询使用b域名的结果比如某些CDN速度的优化此时可以使用cname别名查询功能。
## 配置步骤
1. 使用`cname /a.com/b.com`配置代理服务器
```shell
cname /a.com/b.com
```
上述例子查询a.com时将会使用b.com的查询结果。

52
docs/config/dualstack.md Normal file
View File

@@ -0,0 +1,52 @@
---
hide:
- toc
---
# 双栈优选
目前大部分家庭用户已经有IPV6IPV4双栈网络目前大部分操作系统都会优先使用IPV6网络但某些域名会出现IPV4网络好于IPV6的情况另外一些域名会出现IPV6网络好于IPV4的情况。
SmartDNS提供了双栈优选的功能会自动进行测速优先让客户端操作系统使用速度快的IP地址。
## 配置步骤
1. 使用`dualstack-ip-selection`配置启用双栈优选
```shell
dualstack-ip-selection yes
```
1. 如需要倾向使用IPV6则可以使用`dualstack-ip-selection-threshold`进行阈值调整
```shell
dualstack-ip-selection-threshold 10
```
注意:
1. 单位为ms两个IP地址的速度阈值大于配置值时才会进行优选。
1. 允许纯IPV6地址。
smartdns默认情况下总是会返回IPV4地址原因时某些软件不具备IPV6的访问能力但如果确实需要使用纯IPV6地址可以设置允许smartdns仅优选IPV6。
```shell
dualstack-ip-allow-force-AAAA yes
```
## 特殊应用
某些情况下,可能要临时关闭某些域名的双栈优选,可以通过如下两种方式:
1. 对指定端口查询的域名关闭优选
```shell
bind [::]:53 -no-dualstack-selection
```
1. 对特定域名关闭优选
```shell
domain-rules /example.com/ -dualstack-ip-selection no
```

View File

@@ -48,8 +48,8 @@ flowchart
1. SmartDNS处理请求。
1. 根据namserver给定的规则判断域名
1. 如果域名为内部域名,则使用内部域名服务器查询;如果域名为外部域名,则使用外部域名服务器查询。
1. 内部域名结果使用测速功能获取最快IP地址
1. 外部域名结果获取最快响应DNS结果后将IP地址添加到IPSet/NFTSet中。
1. 内部域名使用测速功能获取最快IP地址。
1. 外部域名获取最快响应DNS结果后将IP地址添加到IPSet/NFTSet中。
1. SmartDNS返回IP地址。
1. 客户端从SmartDNS获取到IP地址。
1. 客户端使用IP地址通过网关请求数据。

View File

@@ -28,6 +28,7 @@ SmartDNS提供了两种测速模式分别是ping和tcp。smartdns默认使用
* ping表示使用ping模式tcp:端口号表示使用tcp链接对应的端口
* none表示不进行测速
* 测速选项的触发: 当配置3种测速模式后smartdns首先用第一种200ms后用第二种400ms后用第三种。
1. 单域名测速模式配置

View File

@@ -83,10 +83,13 @@ nav:
- IPSet和NFTSet: 'config/ipset-nftset.md'
- 通过代理查询: 'config/proxy.md'
- 解析本地主机名: 'config/resolv-dnsmasq-lease.md'
- 缓存设置: 'config/cache.md'
- 双栈优选: 'config/dualstack.md'
- 禁用IPV6: 'config/block-ipv6.md'
- DNS64: 'config/dns64.md'
- 安全相关: 'config/security.md'
- 黑名单分流请求: 'config/forwarding-with-ipset.md'
- cname别名查询: 'config/cname.md'
- 配置选项: 'configuration.md'
- 编译: 'compile.md'
- 常见问题: 'faq.md'