config: add some config guide
This commit is contained in:
@@ -6,4 +6,14 @@ hide:
|
||||
|
||||
# 编译
|
||||
|
||||
## 编译安装包
|
||||
|
||||
SmartDNS 提供了编译软件包的脚本(`package/build-pkg.sh`),支持编译 LuCI、Debian、OpenWrt 和 Optware 安装包。
|
||||
|
||||
## docker镜像
|
||||
|
||||
在源代码根目录执行如下命令
|
||||
|
||||
```shell
|
||||
docker build .
|
||||
```
|
||||
|
||||
80
docs/config/ad-block.md
Normal file
80
docs/config/ad-block.md
Normal file
@@ -0,0 +1,80 @@
|
||||
---
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# 广告屏蔽
|
||||
|
||||
smartdns可以通过指定对应域名返回SOA用于广告屏蔽。
|
||||
|
||||
注意:openwrt有luci的方式,请参考openwrt屏蔽域名配置方法。
|
||||
|
||||
## 基本配置方法
|
||||
|
||||
1. 通过`address /domain/#`选项屏蔽广告,如。
|
||||
|
||||
```shell
|
||||
address /example.com/#
|
||||
```
|
||||
|
||||
address选项中:
|
||||
|
||||
* /domain/为后缀匹配算法,范围包含其子域名。
|
||||
* 单独`#`表示同时屏蔽IPV4, IPV6,
|
||||
* 使用`#6`表示屏蔽IPV6
|
||||
* 使用`#4`表示屏蔽IPV4。
|
||||
* 使用`-`表示不屏蔽此域名。
|
||||
|
||||
1. 如单独屏蔽IPV6
|
||||
|
||||
```shell
|
||||
address /example.com/#6
|
||||
```
|
||||
|
||||
1. 如果想不屏蔽某个子域名
|
||||
|
||||
```shell
|
||||
address /sub.example.com/-
|
||||
```
|
||||
|
||||
## 使用社区已有smartdns广告过滤列表
|
||||
|
||||
社区针对smartdns提供了每日更新的广告列表文件,可以直接使用这些广告列表文件,smartdns可以通过conf-file选项包含广告屏蔽文件。另外在使用这些广告列表文件时,可以定期下载更新文件,并重启smartdns生效。
|
||||
|
||||
1. 下载配置文件到`/etc/smartdns`目录
|
||||
|
||||
```shell
|
||||
wget https://github.com/privacy-protection-tools/anti-AD/blob/master/anti-ad-smartdns.conf -o /etc/smartdns/anti-ad-smartdns.conf
|
||||
```
|
||||
|
||||
1. 修改/etc/smartdns/smartdns.conf文件,包含上述配置文件
|
||||
|
||||
```shell
|
||||
conf-file /etc/smartdns/anti-ad-smartdns.conf
|
||||
```
|
||||
|
||||
## 广告列表
|
||||
|
||||
|项目|说明|配置文件|
|
||||
|--|--|--|
|
||||
|[anti-AD](https://anti-ad.net/)||https://anti-ad.net/anti-ad-for-smartdns.conf|
|
||||
|
||||
## 非smartdns列表
|
||||
|
||||
对于非smartdns的数据,可以通过简单的shell命令进行转换。
|
||||
|
||||
### hosts格式
|
||||
|
||||
如下面命令,可以将`/path/to/hosts/file`的文件(路径换成实际的文件),转换为smartdns支持的格式
|
||||
|
||||
```shell
|
||||
cat /path/to/hosts/file | grep -v "^#" | awk '{print "address /"$2"/#"}' > anti-ad-smartdns.conf
|
||||
```
|
||||
|
||||
### dnsmasq格式
|
||||
|
||||
dnsmasq格式和smartdns类似,但不兼容,可以通过如下命令转换
|
||||
|
||||
```shell
|
||||
cat /path/to/dnsmasq/file | grep address | awk -F= '{print "address "$2"#"}' > anti-ad-smartdns.conf
|
||||
```
|
||||
34
docs/config/block-ipv6.md
Normal file
34
docs/config/block-ipv6.md
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# 禁用IPV6
|
||||
|
||||
目前IPV6已经进入千家万户,但部分情况下,需要禁用IPV6地址,smartdns支持如下方式禁用IPV6地址。
|
||||
|
||||
1. 方法一:完全禁用IPV6
|
||||
|
||||
```shell
|
||||
force-AAAA-SOA yes
|
||||
```
|
||||
|
||||
1. 方法二:禁用特定域名的IPV6
|
||||
|
||||
```shell
|
||||
address /example.com/#6
|
||||
```
|
||||
|
||||
## 其他查询请求的禁用
|
||||
|
||||
smartdns支持对其他查询请求的禁用,对应参数为force-qtype-SOA
|
||||
|
||||
```shell
|
||||
force-qtype-SOA 28
|
||||
```
|
||||
|
||||
force-qtype-SOA参数后为DNS的类型。具体的类型,可以查询[IANA说明](https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4)
|
||||
|
||||
## 附加说明
|
||||
|
||||
smartdns具备自动检测IPV6环境的能力,如果网络环境不支持IPV6,则会自动禁用IPV6相关的优化功能。
|
||||
30
docs/config/bootstrap-dns.md
Normal file
30
docs/config/bootstrap-dns.md
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# Bootstrap DNS
|
||||
|
||||
对于域名类的上游服务器,SmartDNS会使用其他IP地址类的服务器进行解析,所以一般情况下无需配置BootStrap DNS,但如果有特殊需求,需要指定BootStrap DNS,则可以通过如下方式配置:
|
||||
|
||||
1. 方法一:对所有服务器指定bootstrap DNS
|
||||
|
||||
使用`-bootstrap-dns`参数,指定特定的server为bootstrap DNS。
|
||||
|
||||
```shell
|
||||
server 1.2.3.4 -bootstrap-dns
|
||||
server dns.server
|
||||
```
|
||||
|
||||
1. 方法二:针对特定服务器
|
||||
|
||||
使用`nameserver /domain/bootstrap-dns`参数指定特定域名使用指定DNS解析。
|
||||
|
||||
```shell
|
||||
# 配置bootstrap DNS
|
||||
server 1.2.3.4 -group bootstrap-dns
|
||||
nameserver /dns.server/bootstrap-dns
|
||||
# 此服务器将使用1.2.3.4解析
|
||||
server dns.server
|
||||
```
|
||||
|
||||
22
docs/config/dns64.md
Normal file
22
docs/config/dns64.md
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# DNS64
|
||||
|
||||
DNS64用于支持纯IPV6网络访问IPV4网站,smartdns对此也提供了支持,可使用dns64参数配置DNS64服务器。
|
||||
|
||||
## 配置步骤
|
||||
|
||||
1. 使用`dns64 ip/mask`配置代理服务器
|
||||
|
||||
```shell
|
||||
dns64 64:ff9b::/96
|
||||
```
|
||||
|
||||
1. 在纯IPV6的环境下,建议关闭双栈优选功能。
|
||||
|
||||
```shell
|
||||
dualstack-ip-selection no
|
||||
```
|
||||
48
docs/config/domain-forwarding.md
Normal file
48
docs/config/domain-forwarding.md
Normal file
@@ -0,0 +1,48 @@
|
||||
---
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# DNS分流
|
||||
|
||||
smartdns可以支持将特定域名使用特定的 DNS 服务器来查询来做到 DNS 分流。比如
|
||||
|
||||
```shell
|
||||
.home -> 192.168.1.1 # .home 结尾的域名发送到 192.168.1.1 解析
|
||||
.office -> 10.0.0.1 # .office 结尾的域名发送到 10.0.0.1 解析
|
||||
```
|
||||
|
||||
其他域名采用默认的模式解析,这种情况的分流配置如下:
|
||||
|
||||
## 配置步骤
|
||||
|
||||
1. 配置上游服务器组,并对上游使用`-group`进行分组
|
||||
|
||||
```shell
|
||||
# 配置上游,用 -group 指定组名,用 -exclude-default-group 将服务器从默认组中排除。
|
||||
server 192.168.1.1 -group home -exclude-default-group
|
||||
server 10.0.0.1 -group office -exclude-default-group
|
||||
server 8.8.8.8
|
||||
```
|
||||
|
||||
1. 配置对应域名解析时使用的服务器组
|
||||
|
||||
```shell
|
||||
# 上游服务器规则,.home结尾的域名全部使用home组的服务器查询
|
||||
nameserver /home/home
|
||||
# 上游服务器规则,.office结尾的域名全部使用office组查询。
|
||||
nameserver /office/office
|
||||
```
|
||||
|
||||
类似的,home可以换成domestic,office可以换成oversea
|
||||
|
||||
## 更多能力
|
||||
|
||||
通过上述配置即可实现 DNS 解析分流后,如果需要实现按请求端端口分流,可以配置第二 DNS 服务器,`bind` 配置增加 `--group` 参数指定分流名称。
|
||||
|
||||
```shell
|
||||
bind :7053 -group office
|
||||
bind :8053 -group home
|
||||
```
|
||||
|
||||
通过上述配置,到7053端口查询的请求,全部使用office查询,到8053端口查询的请求,全部使用home查询。
|
||||
29
docs/config/domain-set.md
Normal file
29
docs/config/domain-set.md
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# 域名集合的使用
|
||||
|
||||
为方便按集合配置域名,对于有/domain/的配置,可以指定域名集合,方便维护。具体方法为:
|
||||
|
||||
1. 使用`domain-set`配置集合文件,如
|
||||
|
||||
```shell
|
||||
domain-set -name ad -file /etc/smartdns/ad-list.conf
|
||||
```
|
||||
|
||||
ad-list.conf的格式为一个域名一行,如
|
||||
|
||||
```shell
|
||||
ad.com
|
||||
site.com
|
||||
```
|
||||
|
||||
1. 在有/domain/配置的选项使用域名集合,只需要将`/domain/`配置为`/domain-set:[集合名称]/`即可,如:
|
||||
|
||||
```shell
|
||||
address /domain-set:ad/#
|
||||
domain-rules /domain-set:ad/ -a #
|
||||
nameserver /domain-set:ad/server
|
||||
```
|
||||
88
docs/config/ipset-nftset.md
Normal file
88
docs/config/ipset-nftset.md
Normal file
@@ -0,0 +1,88 @@
|
||||
---
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# 使用ipset和nftset
|
||||
|
||||
和Dnsmasq类似,smartdns支持ipset和nftset,可以将特定的域名通过TPROXY进行透明转发,透明转发涉工具模式对比如下:
|
||||
|
||||
1. 工具:iptable,nftable
|
||||
|
||||
iptable:成熟的路由规则配置工具。
|
||||
nftable:更加强大的规则配置工具,正在成为主流。
|
||||
|
||||
1. 模式:TPROXY,REDIRECT
|
||||
|
||||
TPROXY:支持UDP,TCP的转发,配置稍复杂。
|
||||
REDIRECT:仅支持TCP,配置简单。
|
||||
|
||||
1. 配置REDIRECT或TPROXY转发规则
|
||||
|
||||
在smartdns.conf中设置需要透明转发的域名列表,比如要将`example.com`进行透明转发。则使用ipset选项,设置`example.com`的ipset规则为`proxy`。
|
||||
|
||||
```shell
|
||||
# 设置规则
|
||||
# -ipset proxy: 匹配的域名设置到ipset:tproxy中。
|
||||
# -c none: 停用测速
|
||||
# -address #6: 停用IPV6解析。
|
||||
domain-rules /example.com/ -ipset proxy -c none -address #6
|
||||
```
|
||||
|
||||
1. 方式一: TCP REDIRECT转发
|
||||
|
||||
- 此方式配置简单,仅支持TCP的转发。
|
||||
执行shell命令,设置iptable规则,如果仅转发TCP则可以直接使用REDIRECT的规则,如果需要同时转发UDP和TCP,可以使用TPROXY的转发规则。如下规则按实际需求选择。具体配置如下:
|
||||
|
||||
```shell
|
||||
# 创建ipset集合
|
||||
ipset create proxy hash:net
|
||||
# 设置转发规则,将匹配的请求转发到本机的1081端口
|
||||
iptables -t nat -I PREROUTING -p tcp -m set --match-set proxy dst -j REDIRECT --to-ports 1081
|
||||
```
|
||||
|
||||
- 在本机1081端口开启REDIRECT模式的转发程序。
|
||||
|
||||
1. 方式二:TCP/UDP TPROXY转发
|
||||
|
||||
- 此方式可同时转发TCP和UDP。
|
||||
执行shell命令,设置iptable规则,将匹配的域名TCP/UDP请求进行TPROXY方式透明转发,规则参考如下:
|
||||
|
||||
```shell
|
||||
# 设置路由规则
|
||||
ip rule add fwmark 1104 lookup 1104
|
||||
ip route add local 0.0.0.0/0 dev lo table 1104
|
||||
|
||||
# 创建ipset集合
|
||||
ipset create proxy hash:net
|
||||
|
||||
# 设置转发规则,UDP,TCP方式的TPROXY转发
|
||||
iptables -t mangle -N SMARTDNS
|
||||
iptables -t mangle -A SMARTDNS -p tcp -m set --match-set proxy dst -j TPROXY --on-ip 127.0.0.1 --on-port 1081 --tproxy-mark 1104
|
||||
iptables -t mangle -A SMARTDNS -p udp -m set --match-set proxy dst -j TPROXY --on-ip 127.0.0.1 --on-port 1081 --tproxy-mark 1104
|
||||
iptables -t mangle -A SMARTDNS -j ACCEPT
|
||||
iptables -t mangle -A PREROUTING -j SMARTDNS
|
||||
```
|
||||
|
||||
- 在本机的1081端口启动IP透明转发程序。
|
||||
|
||||
1. 额外说明
|
||||
|
||||
- 为保证DNS查询结果的位置亲和性,可以使用smartdns的`server`代理参数,将对应域名的查询请求,通过代理查询,使结果位置更好。如:
|
||||
|
||||
```shell
|
||||
# 增加DNS上游,并设置通过名称为proxy的代理查询,查询组为pass
|
||||
server 1.2.3.4 -proxy proxy -group pass -exclude-default-group
|
||||
# 设置代理服务器信息,代理的名称为proxy
|
||||
proxy-server socks5://user:name@1.2.3.4 -name proxy
|
||||
# 设置域名规则,对匹配的域名使用代理查询结果,并将结果设置到ipset中。
|
||||
domain-rules /example.com/ -ipset proxy -c none -address #6 -nameserver pass
|
||||
```
|
||||
|
||||
- 如需要配合测速自动完成ipset的设置,可增加如下配置参数
|
||||
|
||||
```shell
|
||||
ipset-no-speed proxy
|
||||
```
|
||||
|
||||
如果使用OpenWrt的luci界面,可以直接在界面配置相关的域名分流规则。
|
||||
24
docs/config/proxy.md
Normal file
24
docs/config/proxy.md
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# 通过代理查询
|
||||
|
||||
smartdns支持通过代理服务器进行查询,支持的代理服务器有socks5和http代理服务器。socks5支持udp和tcp类型的代理,而http不支持udp代理,注意区分。
|
||||
|
||||
## 配置步骤
|
||||
|
||||
1. 使用`proxy-server`配置代理服务器
|
||||
|
||||
```shell
|
||||
proxy-server socks5://1.2.3.4 -name socks5
|
||||
```
|
||||
|
||||
1. 使用`-proxy`参数,配置server使用代理服务器:
|
||||
|
||||
```shell
|
||||
server 8.8.8.8 -proxy socks5
|
||||
```
|
||||
|
||||
注意proxy-server的`-name`和server的`-proxy`须为同一个名称。
|
||||
18
docs/config/resolv-dnsmasq-lease.md
Normal file
18
docs/config/resolv-dnsmasq-lease.md
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# 解析本地主机名称
|
||||
|
||||
smartdns可以配合DNSMASQ的dhcp lease文件支持本地主机名->IP地址的解析,可以配置smartdns读取dnsmasq的lease文件,并支持解析。具体配置参数如下
|
||||
(注意,DNSMASQ lease文件每个系统可能不一样,需要按实际情况配置)
|
||||
|
||||
```shell
|
||||
dnsmasq-lease-file /var/lib/misc/dnsmasq.leases
|
||||
```
|
||||
|
||||
配置完成后,可以直接使用主机名连接对应的机器。但需要注意:
|
||||
|
||||
1. Windows系统默认使用mDNS解析地址,如需要在windows下用使用smartdns解析,则需要在主机名后面增加`.`,表示使用DNS解析。如`ping smartdns.`
|
||||
1. smartdns会周期监控文件变化,并自动加载变化的映射关系。
|
||||
40
docs/config/security.md
Normal file
40
docs/config/security.md
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# 安全相关
|
||||
|
||||
smartdns为DNS服务器,默认绑定53端口,这时smartdns需要root权限,并且有可能导致外网也能进行数据查询。所以通过如下方式对smartdns进行安全加固
|
||||
|
||||
## 使用非root权限运行
|
||||
|
||||
通过user指定非root用户运行,如使用nobody运行
|
||||
|
||||
```shell
|
||||
user nobody
|
||||
```
|
||||
|
||||
## 绑定特定的IP或网口
|
||||
|
||||
通过bind参数,指定绑定的IP地址,或网口
|
||||
|
||||
1. 绑定特定的IP
|
||||
|
||||
```shell
|
||||
bind 192.168.1.1:53
|
||||
```
|
||||
|
||||
1. 绑定特定的网口
|
||||
|
||||
```shell
|
||||
bind [::]:53@eth0
|
||||
```
|
||||
|
||||
## 对公网提供查询时,使用TLS服务器
|
||||
|
||||
使用TLS服务器对外提供服务
|
||||
|
||||
```shell
|
||||
bind-tls [::]:853@eth0
|
||||
```
|
||||
62
docs/config/work-mode.md
Normal file
62
docs/config/work-mode.md
Normal file
@@ -0,0 +1,62 @@
|
||||
---
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# 工作模式
|
||||
|
||||
smartdns可修改测速模式,和数据响应模式。这两种模式影响查询的性能和效果。
|
||||
|
||||
|模式|参数|说明|
|
||||
|---|---|---
|
||||
|测速模式|speed-check-mode|smartdns速度检测模式
|
||||
|响应模式|response-mode|结果回应模式|
|
||||
|
||||
## 测速模式
|
||||
|
||||
SmartDNS提供了两种测速模式,分别是ping和tcp。smartdns默认使用三次测速。第一次为ping,第二次为tcp的80端口,第三次为tcp的443端口,可通过speed-check-mode修改测速模式
|
||||
|
||||
1. 全局测速模式配置
|
||||
|
||||
```shell
|
||||
speed-check-mode ping,tcp:80,tcp:443
|
||||
speed-check-mode tcp:443,ping
|
||||
speed-check-mode none
|
||||
```
|
||||
|
||||
选项中:
|
||||
|
||||
* ping表示使用ping模式,tcp:端口号,表示使用tcp链接对应的端口
|
||||
* none表示不进行测速
|
||||
|
||||
1. 单域名测速模式配置
|
||||
|
||||
```shell
|
||||
domain-rule /example.com/ -speed-check-mode ping,tcp:80,tcp:443
|
||||
```
|
||||
|
||||
1. 对应端口查询时关闭测速
|
||||
|
||||
```shell
|
||||
bind [::]:53 -no-speed-check
|
||||
```
|
||||
|
||||
1. 额外的
|
||||
|
||||
如果分流的域名通过转发程序转发,则考虑关闭转发域名的测速功能,避免测速和出口不一致导致的体验反作用,关闭特定域名的测速方式如下:
|
||||
|
||||
```shell
|
||||
domain-rule /example.com/ -speed-check-mode none
|
||||
```
|
||||
|
||||
## 响应模式配置
|
||||
|
||||
Smartdns支持通过`response-mode`设置首次请求响应模式,这三中模式影响查询结果和响应时间,smartdns默认使用了优化方案,但用户也可根据需要进行修改;这三种模式对应的功能和性能如下:
|
||||
|
||||
|模式|配置项|时延|结果|说明
|
||||
|---|---|---|---|---
|
||||
|最快ping响应地址模式|first-ping|适中|可能次佳|DNS上游最快查询时延+ping时延最短,查询等待与链接体验最佳。(当前默认)
|
||||
|最快IP地址模式|fastest-ip|长|最佳|查询到的所有IP地址中ping最短的IP。DNS查询时间最长,IP链接最短。(之前模式)
|
||||
|最快响应的DNS模式|fastest-response|短|可能最差|DNS查询等待时间最短。
|
||||
|
||||
对于开启了缓存功能后,缓存后的数据,无论使用哪种方式,其结果时最佳的,所以不建议关闭缓存。
|
||||
194
docs/faq.md
194
docs/faq.md
@@ -44,50 +44,6 @@ SmartDNS 有测速机制,在配置上游服务器时,建议配置多个上
|
||||
- 优先使用 TLS 查询。
|
||||
- 设置上游 DNS 服务器组。
|
||||
|
||||
## 如何屏蔽广告?
|
||||
|
||||
SmartDNS 具备高性能域名匹配算法,通过域名方式过滤广告非常高效,如要屏蔽广告,只需要配置类似如下记录即可,如,屏蔽 `*.ad.com`,则配置:
|
||||
|
||||
```shell
|
||||
address /ad.com/#
|
||||
```
|
||||
|
||||
域名的使后缀模式,过滤 `*.ad.com`,`#` 表示返回 SOA,使屏蔽广告更加高效,如果要单独屏蔽 IPv4 或 IPv6, 在 `#` 后面增加数字,如 `#4` 表示对 IPv4 生效。若想忽略特定子域名的屏蔽,如忽略 `pass.ad.com`,可配置如下:
|
||||
|
||||
```shell
|
||||
address /pass.ad.com/-
|
||||
```
|
||||
|
||||
## 如何使用 DNS 查询分流?
|
||||
|
||||
某些情况下,需要将有些域名使用特定的 DNS 服务器来查询来做到 DNS 分流。比如
|
||||
|
||||
```shell
|
||||
.home -> 192.168.1.1 # .home 结尾的域名发送到 192.168.1.1 解析
|
||||
.office -> 10.0.0.1 # .office 结尾的域名发送到 10.0.0.1 解析
|
||||
```
|
||||
|
||||
其他域名采用默认的模式解析。
|
||||
这种情况的分流配置如下:
|
||||
|
||||
```shell
|
||||
# 配置上游,用 -group 指定组名,用 -exclude-default-group 将服务器从默认组中排除。
|
||||
server 192.168.1.1 -group home -exclude-default-group
|
||||
server 10.0.0.1 -group office -exclude-default-group
|
||||
server 8.8.8.8
|
||||
|
||||
# 配置解析的域名
|
||||
nameserver /.home/home
|
||||
nameserver /.office/office
|
||||
```
|
||||
|
||||
通过上述配置即可实现 DNS 解析分流,如果需要实现按请求端端口分流,可以配置第二 DNS 服务器,`bind` 配置增加 `--group` 参数指定分流名称。
|
||||
|
||||
```shell
|
||||
bind :7053 -group office
|
||||
bind :8053 -group home
|
||||
```
|
||||
|
||||
## IPv4、IPv6 双栈 IP 优选功能如何使用?
|
||||
|
||||
目前 IPv6 已经开始普及,但 IPv6 网络在速度上,某些情况下还不如 IPv4。为在双栈网络下获得较好的体验,SmartDNS 提供来双栈IP优选机制,同一个域名,若 IPv4 的速度远快与 IPv6,那么 SmartDNS 就会阻止IPv6的解析、使用 IPv4 访问。可在配置文件中通过设置 `dualstack-ip-selection yes` 启用此功能,通过 `dualstack-ip-selection-threshold [time]` 来修改阈值。如果要完全禁止 IPv6 AAAA记录解析,可设置 `force-AAAA-SOA yes`。
|
||||
@@ -145,150 +101,20 @@ IOS14开始,苹果支持了DNS HTTPS(TYPE65)记录的解析,此功能用于
|
||||
force-qtype-SOA 65
|
||||
```
|
||||
|
||||
## 如何解析本地主机名称?
|
||||
## 为什么smartdns会返回多个IP
|
||||
|
||||
smartdns可以配合DNSMASQ的dhcp lease文件支持本地主机名->IP地址的解析,可以配置smartdns读取dnsmasq的lease文件,并支持解析。具体配置参数如下,(注意,DNSMASQ lease文件每个系统可能不一样,需要按实际情况配置)
|
||||
SmartDNS在早期版本,只会返回一个IP地址,这一个IP地址速度时最快的,这对游戏,浏览器都很好,但对于一些视频播放软件,下载软件则不太友好。这些软件需要更多好的IP地址。
|
||||
|
||||
```shell
|
||||
dnsmasq-lease-file /var/lib/misc/dnsmasq.leases
|
||||
```
|
||||
所以,smartdns从37开始,支持返回多个优选的IP地址,这些优选的IP地址原则是:
|
||||
|
||||
配置完成后,可以直接使用主机名连接对应的机器。但需要注意:
|
||||
1. 如果缓存没有命中,则返回及时返回一个IP地址给客户端,并设置TTL为3,让客户端再次查询。
|
||||
1. 并行的,smartdns等待所有IP地址的查询结果,并对查询结果进行优选。原则为:
|
||||
- IP列表中的第一个IP为最快地址。
|
||||
- 其他IP相比第一个IP的速度差不多。
|
||||
- 速度较差的IP丢弃。
|
||||
1. 客户端3秒后,再次查询,将会获的所有最佳IP地址。
|
||||
|
||||
- Windows系统默认使用mDNS解析地址,如需要在windows下用使用smartdns解析,则需要在主机名后面增加`.`,表示使用DNS解析。如`ping smartdns.`
|
||||
|
||||
## 域名集合如何使用?
|
||||
|
||||
为方便按集合配置域名,对于有/domain/的配置,可以指定域名集合,方便维护。具体方法为:
|
||||
|
||||
- 使用`domain-set`配置集合文件,如
|
||||
|
||||
```shell
|
||||
domain-set -name ad -file /etc/smartdns/ad-list.conf
|
||||
```
|
||||
|
||||
ad-list.conf的格式为一个域名一行,如
|
||||
|
||||
```shell
|
||||
ad.com
|
||||
site.com
|
||||
```
|
||||
|
||||
- 在有/domain/配置的选项使用域名集合,只需要将`/domain/`配置为`/domain-set:[集合名称]/`即可,如:
|
||||
|
||||
```shell
|
||||
address /domain-set:ad/#
|
||||
domain-rules /domain-set:ad/ -a #
|
||||
nameserver /domain-set:ad/server
|
||||
...
|
||||
```
|
||||
|
||||
## 如何使用ipset和nftset
|
||||
|
||||
和Dnsmasq类似,smartdns支持ipset和nftset,可以将特定的域名通过TPROXY进行透明转发,透明转发涉工具模式对比如下:
|
||||
|
||||
1. 工具:iptable,nftable
|
||||
|
||||
iptable:成熟的路由规则配置工具。
|
||||
nftable:更加强大的规则配置工具,正在成为主流。
|
||||
|
||||
1. 模式:TPROXY,REDIRECT
|
||||
|
||||
TPROXY:支持UDP,TCP的转发,配置稍复杂。
|
||||
REDIRECT:仅支持TCP,配置简单。
|
||||
|
||||
1. 配置REDIRECT或TPROXY转发规则
|
||||
|
||||
在smartdns.conf中设置需要透明转发的域名列表,比如要将`example.com`进行透明转发。则使用ipset选项,设置`example.com`的ipset规则为`proxy`。
|
||||
|
||||
```shell
|
||||
# 设置规则
|
||||
# -ipset proxy: 匹配的域名设置到ipset:tproxy中。
|
||||
# -c none: 停用测速
|
||||
# -address #6: 停用IPV6解析。
|
||||
domain-rules /example.com/ -ipset proxy -c none -address #6
|
||||
```
|
||||
|
||||
1. 方式一: TCP REDIRECT转发
|
||||
|
||||
- 此方式配置简单,仅支持TCP的转发。
|
||||
执行shell命令,设置iptable规则,如果仅转发TCP则可以直接使用REDIRECT的规则,如果需要同时转发UDP和TCP,可以使用TPROXY的转发规则。如下规则按实际需求选择。具体配置如下:
|
||||
|
||||
```shell
|
||||
# 创建ipset集合
|
||||
ipset create proxy hash:net
|
||||
# 设置转发规则,将匹配的请求转发到本机的1081端口
|
||||
iptables -t nat -I PREROUTING -p tcp -m set --match-set proxy dst -j REDIRECT --to-ports 1081
|
||||
```
|
||||
|
||||
- 在本机1081端口开启REDIRECT模式的转发程序。
|
||||
|
||||
1. 方式二:TCP/UDP TPROXY转发
|
||||
|
||||
- 此方式可同时转发TCP和UDP。
|
||||
执行shell命令,设置iptable规则,将匹配的域名TCP/UDP请求进行TPROXY方式透明转发,规则参考如下:
|
||||
|
||||
```shell
|
||||
# 设置路由规则
|
||||
ip rule add fwmark 1104 lookup 1104
|
||||
ip route add local 0.0.0.0/0 dev lo table 1104
|
||||
|
||||
# 创建ipset集合
|
||||
ipset create proxy hash:net
|
||||
|
||||
# 设置转发规则,UDP,TCP方式的TPROXY转发
|
||||
iptables -t mangle -N SMARTDNS
|
||||
iptables -t mangle -A SMARTDNS -p tcp -m set --match-set proxy dst -j TPROXY --on-ip 127.0.0.1 --on-port 1081 --tproxy-mark 1104
|
||||
iptables -t mangle -A SMARTDNS -p udp -m set --match-set proxy dst -j TPROXY --on-ip 127.0.0.1 --on-port 1081 --tproxy-mark 1104
|
||||
iptables -t mangle -A SMARTDNS -j ACCEPT
|
||||
iptables -t mangle -A PREROUTING -j SMARTDNS
|
||||
```
|
||||
|
||||
- 在本机的1081端口启动IP透明转发程序。
|
||||
|
||||
1. 额外说明
|
||||
|
||||
- 为保证DNS查询结果的位置亲和性,可以使用smartdns的`server`代理参数,将对应域名的查询请求,通过代理查询,使结果位置更好。如:
|
||||
|
||||
```shell
|
||||
# 增加DNS上游,并设置通过名称为proxy的代理查询,查询组为pass
|
||||
server 1.2.3.4 -proxy proxy -group pass -exclude-default-group
|
||||
# 设置代理服务器信息,代理的名称为proxy
|
||||
proxy-server socks5://user:name@1.2.3.4 -name proxy
|
||||
# 设置域名规则,对匹配的域名使用代理查询结果,并将结果设置到ipset中。
|
||||
domain-rules /example.com/ -ipset proxy -c none -address #6 -nameserver pass
|
||||
```
|
||||
|
||||
- 如需要配合测速自动完成ipset的设置,可增加如下配置参数
|
||||
|
||||
```shell
|
||||
ipset-no-speed proxy
|
||||
```
|
||||
|
||||
如果使用OpenWrt的luci界面,可以直接在界面配置相关的域名分流规则。
|
||||
|
||||
## BootStrap DNS
|
||||
|
||||
对于域名类的上游服务器,SmartDNS会使用其他IP地址类的服务器进行解析,所以一般情况下无需配置BootStrap DNS,但如果有特殊需求,需要指定BootStrap DNS。则可以通过如下方式配置:
|
||||
|
||||
1. nameserver指定上游服务器
|
||||
|
||||
使用nameserver参数指定特定域名使用指定DNS解析。
|
||||
|
||||
```shell
|
||||
server dns.server # 此服务器将使用1.2.3.4解析。
|
||||
server 1.2.3.4 -group bootstrap
|
||||
nameserver /dns.server/bootstrap
|
||||
```
|
||||
|
||||
1. 对所有服务器指定bootstrap DNS。
|
||||
|
||||
使用`-bootstrap-dns`参数,指定特定的server为bootstrap DNS。
|
||||
|
||||
```shell
|
||||
server 1.2.3.4 -bootstrap-dns
|
||||
server dns.server
|
||||
```
|
||||
值得注意的是,上述机制,是在开启了缓存的情况下,如果缓存未开启,则仍然返回最快的一个地址。
|
||||
|
||||
## 更多问题
|
||||
|
||||
|
||||
12
mkdocs.yml
12
mkdocs.yml
@@ -70,6 +70,18 @@ nav:
|
||||
- 华硕固件 / 梅林固件: 'install/asus.md'
|
||||
- EntWare: 'install/entware.md'
|
||||
- WSL: 'install/wsl.md'
|
||||
- 配置示例:
|
||||
- 屏蔽广告: 'config/ad-block.md'
|
||||
- DNS分流: 'config/domain-forwarding.md'
|
||||
- 工作模式: 'config/work-mode.md'
|
||||
- Bootstrap DNS: 'config/bootstrap-dns.md'
|
||||
- 域名集合: 'config/domain-set.md'
|
||||
- IPSet和NFTSet: 'config/ipset-nftset.md'
|
||||
- 通过代理查询: 'config/proxy.md'
|
||||
- 解析本地主机名: 'config/resolv-dnsmasq-lease.md'
|
||||
- 禁用IPV6: 'config/block-ipv6.md'
|
||||
- DNS64: 'config/dns64.md'
|
||||
- 安全相关: 'config/security.md'
|
||||
- 配置选项: 'configuration.md'
|
||||
- 编译: 'compile.md'
|
||||
- 常见问题: 'faq.md'
|
||||
|
||||
Reference in New Issue
Block a user