项目地址 https://github.com/pymumu/smartdns
文档 https://pymumu.github.io/smartdns/
1.安装
Debian12 下载 Releases中deb安装包,使用命令安装
dpkg -i smartdns.1.yyyy.MM.dd-REL.arm-debian-all.deb
注意Linux发行版是否存在53端口占用,可以使用
sudo ss -lnptu | grep :53
查看53端口监听情况。
2.配置文件
Debian的配置文件smartdns.conf
在/etc/smartdns
目录下
主要能用到的选项有
# 监听53端口
server-name smartdns
bind [::]:53
# 配置上游服务器,支持几乎所有DNS类型
server 8.8.8.8
server 1.1.1.1
server 9.9.9.9
server 64.6.64.6
server 80.80.80.80
server 208.67.222.222
#cache-size为缓存条数,不写会根据系统内存情况自动设置
cache-size 32768
cache-persist yes
cache-file /etc/smartdns/list.cache
#下面为开启缓存域名预获取,并缓存3天,期间每6小时重新向所有配置的上游获取一次
prefetch-domain yes
serve-expired-prefetch-time 21600
serve-expired yes
serve-expired-ttl 259200
serve-expired-reply-ttl 3
cache-checkpoint-time 86400
#DNS不返回IPV6地址,有需要再开启
#force-AAAA-SOA yes
#SmartDNS提供了两种测速模式,分别是ping和tcp。smartdns默认使用三次测速。第一次为ping,第二次为tcp的80端口,第三次为tcp的443端口
#smartdns会将最佳结果保存到缓存中
speed-check-mode ping,tcp:80,tcp:443
上述示例为海外VPS,国内机自行修改。
可用DNS服务器 https://dns.iui.im/
3.启动DNS服务器
systemctl enable smartdns
systemctl start smartdns
后续配置更改后,需要重启smartdns
systemctl restart smartdns
4.修改本机DNS
修改/etc/resolv.conf
,只留nameserver 127.0.0.1
5.查询
执行
nslookup -querytype=ptr smartdns
查看命令结果中的 name
是否为 smartdns
或你的主机名,如果是则表示生效
$ nslookup -querytype=ptr smartdns
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
smartdns name = smartdns.
如果没有nslookup
安装一下
apt update
apt install dnsutils
可以对比一下smartdns和其他公共dns的查询结果
#使用本机127.0.0.1:53查询
nslookup www.bilibili.com
#使用GoogleDNS查询
nslookup www.bilibili.com 8.8.8.8