方永、南天紫云

道亦有道

OpenWrt上SmartDNS的一个有效配置
2024年03月31日

SmartDNS功能强大,协议全面,OpenWrt上的支持也很完备, 是很多人主用的 dns server。

因为需要分组解析域名的功能,虽然dnsmasq也能实现,但SmartDNS的配置更为简洁,支持一组域名从文件中读的功能,并可以为这个组的域名统一设置解析规则。当然也有chinadns-ng这样的工具可以一试。

在OpenWrt上使用时,遇到一个问题,就是上游服务器可正确解析,但是SmartDNS返回A记录是空。 尝试关闭 serve expired,关闭 cache persist,目前可正常工作。

配置如下:

/var/etc/smartdns/smartdns.conf

server-name smartdns
speed-check-mode tcp:443,tcp:80,ping
cache-size 20000
dnsmasq-lease-file /tmp/dhcp.leases
rr-ttl 3600
rr-ttl-min 5
log-size 64K
log-num 1
log-level error
audit-size 64K
audit-num 1
cache-persist no
force-qtype-SOA  65
resolv-file /tmp/resolv.conf.d/resolv.conf.auto
bind [::]:53@br-lan
bind [::]:53@lo
server 114.114.114.114
domain-set -name domain-block-list -file /etc/smartdns/domain-block.list
domain-rules /domain-set:domain-block-list/ -address #
conf-file /etc/smartdns/address.conf
conf-file /etc/smartdns/blacklist-ip.conf
conf-file /etc/smartdns/custom.conf

/etc/smartdns/address.conf, /etc/smartdns/blacklist-ip.conf

/etc/smartdns/custom.conf

server 10.0.0.2 -group fq -exclude-default-group
address /router.lan/192.168.1.1
domain-set -name fq -type list -file fq.list
domain-rules /domain-set:fq/ -nameserver fq -nftset #4:inet#fw4#fq

fq 组上游服务器10.0.0.2是WireGuard的peer地址,在此机器上配置端口转发,即53端口转发到 1.1.1.1,这样能保证域名解析和路由 path 是同一出口。