小米官方固件中集成smartdns
1.下载二进制文件
如小米ax3600,构架为aarch64.
2.安装目录
将二进制文件重命名为 smartdns
复制到 /etc/smartdns/ 目录下
chmod +x /etc/smartdns/smartdns
3.配置文件smartdns.conf
新建一个文件,命名为 smartdns.conf,同 /etc/smartdns/ 下
示例参数
bind [::]:5353
bind-tcp [::]:5353
cache-size 1024k
prefetch-domain yes
serve-expired yes
force-AAAA-SOA no
force-qtype-SOA 65
server-https https://cn-east.iqiqzz.com/cdn
server-tls cn-east.iqiqzz.com:853
server-https https://1.12.12.12/dns-query
server-https https://dns.alidns.com/dns-query
server 2400:3200::1
server 2402:4e00::
speed-check-mode ping,tcp:443,tcp:80
response-mode fastest-ip
dualstack-ip-selection yes
dualstack-ip-selection-threshold 20
max-reply-ip-num 1
4.重定向防火墙53端口至5353
1.重定向 tcp 和 udp 53 端口
#ipv4
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
#ipv6
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5353
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5353
2.保存防火墙配置
#ipv4防火墙
iptables-save >/etc/iptables-script
iptables-restore </etc/iptables-script
#ipv6防火墙
ip6tables-save >/etc/ip6tables-script
ip6tables-restore </etc/ip6tables-script
3.防火墙开机生效
编辑文件
vi /etc/rc.local
在 exit0 前面输入
/usr/sbin/iptables-restore </etc/iptables-script
/usr/sbin/ip6tables-restore </etc/ip6tables-script
5.配置smartdns开机启动
ssh 运行以下命令
ln -s /etc/smartdns/smartdns /etc/rc.d/S999smartdns
6.(可选)去广告并自动更新规则
1.在 /etc/smartdns/ 目录下新建文件 smartdns_update.sh 写入如下
## 切换到 SmartDNS 服务配置目录
cd /etc/smartdns
## 删除旧的规则文件
rm -rf smartdns-dns.conf
## 下载新规则文件
curl -Ok https://adrules.top/smart-dns.conf
## 重启 SmartDNS 服务 使规则生效
/etc/smartdns/smartdns restart
chmod +x /etc/smartdns/smartdns_update.sh
2.修改smartdns.conf,引用规则文件
新增一行
conf-file /etc/smartdns/smart-dns.conf
运行一次脚本
./etc/smartdns/smartdns_update.sh