文章介绍:以下内容是个人使用的标准DNS分流模板,通过谷歌+官网配置文档综合而成,已经试运行20多天,功能皆满足日常使用,今天来分享一下关于smartdns在ubuntu中的具体配置方式,如果感兴趣可以进交流群互助。
一、安装
1.1、install安装
sudo apt-get install -y smartdns
1.2、deb包安装
uname -m
命令查看系统是什么架构,比如我的是x86_64位。
root@test-server:~# uname -m
x86_64
wget -O smartdns.deb https://github.com/pymumu/smartdns/releases/download/Release45/smartdns.1.2024.02.08-0828.x86_64-debian-all.deb
dpkg -i smartdns.deb
wget -O smartdns.deb https://github.com/pymumu/smartdns/releases/download/Release45/smartdns.1.2024.02.08-0828.x86-debian-all.deb
wget -O smartdns.deb https://github.com/pymumu/smartdns/releases/download/Release45/smartdns.1.2024.02.08-0828.arm-debian-all.deb
wget -O smartdns.deb https://github.com/pymumu/smartdns/releases/download/Release45/smartdns.1.2024.02.08-0828.aarch64-debian-all.deb
https://github.com/pymumu/smartdns/releases/download/Release45/smartdns.1.2024.02.08-0828.mips-debian-all.deb
二、系统优化
2.1、查看53端口占用情况
netstat -atunp | grep 53
2.2、停止系统systemd-resolved
服务
sudo systemctl stop systemd-resolved
2.3、禁用 systemd-resolved
服务
sudo systemctl disable systemd-resolved
2.4、再次查看53端口占用情况
ss -atunp | grep 53
三、配置smartdns
3.1、进入主目录
cd /etc/smartdns
3.2、查看smartdns默认配置
cat smartdns.conf |grep '^[^#|^;]'
3.3、删除默认配置文件
rm smartdns.conf
3.4、创建新配置文件
touch smartdns.conf;chmod +644 smartdns.conf;nano smartdns.conf
bind [::]:53
bind-tcp [::]:53
force-qtype-SOA 65
log-level info
server 223.5.5.5
server 8.8.8.8
3.5、启动服务
sudo systemctl start smartdns
3.6、检查53端口
ss -atunp | grep 53
3.7、下载大陆域名
wget https://raw.githubusercontent.com/HMBSbige/Text_Translation/master/chndomains.txt -O /etc/smartdns/domestic_domainlist.conf
3.8、下载海外域名
wget https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/gfw.txt -O /etc/smartdns/oversea_domainlist.conf
3.9、升级配置
# DNS服务器名称
server-name smartdns
# 全局DNS服务端口(禁用IPV6查询)
bind :53 -force-aaaa-soa
bind-tcp :53 -force-aaaa-soa
# 设置海外-oversea组-DNS列表
server 8.8.8.8 -group oversea
server 8.8.4.4 -group oversea
server 1.0.0.1 -group oversea
server 9.9.9.9 -group oversea
# 设置大陆-domestic组-DNS列表(从默认DNS组排除,当解析到不在下面三个域名列表内的域名时,使用oversea组和chatgpt组DNS解析)
server 202.96.209.133 -group domestic -exclude-default-group
server 180.168.255.118 -group domestic -exclude-default-group
server 116.228.111.118 -group domestic -exclude-default-group
server 202.96.209.5 -group domestic -exclude-default-group
# 设置OpenAI-chatgpt组-DNS列表
server 208.67.222.222 -group chatgpt
server 208.67.220.220 -group chatgpt
server 209.244.0.4 -group chatgpt
server 209.244.0.3 -group chatgpt
# 设置大陆域名集:domestic_domainlist,映射到:/etc/smartdns/domestic_domainlist.conf
domain-set -name domestic_domainlist -file /etc/smartdns/domestic_domainlist.conf
# 设置海外域名集:oversea_domainlist,映射到:/etc/smartdns/oversea_domainlist.conf
domain-set -name oversea_domainlist -file /etc/smartdns/oversea_domainlist.conf
# 设置GPT域名集:chatgpt_domainlist,映射到:/etc/smartdns/chatgpt_domainlist.conf
domain-set -name chatgpt_domainlist -file /etc/smartdns/chatgpt_domainlist.conf
# 指定大陆域名集:使用domestic组-DNS解析(大陆测速)
domain-rules /domain-set:domestic_domainlist/ -nameserver domestic -speed-check-mode ping,tcp:80,tcp:443
# 指定GPT域名集:使用chatgpt组-DNS解析(海外不测速)
domain-rules /domain-set:chatgpt_domainlist/ -nameserver chatgpt -speed-check-mode none
# 指定海外域名集:使用oversea组-DNS解析(GPT不测速)
domain-rules /domain-set:oversea_domainlist/ -nameserver oversea -speed-check-mode none
# 日志(系统+审计)
log-level debug
log-size 50m
log-file /tmp/smartdns.log
log-num 8
audit-enable yes
audit-file /tmp/smartdns-audit.log
audit-size 50m
audit-num 2
# 缓存配置
cache-size 32768
cache-persist yes
prefetch-domain yes
cache-file /tmp/smartdns.cache
# 开启过期缓存服务功能
serve-expired yes
# 设定过期缓存服务最长超时时间(秒)
serve-expired-ttl 3
# 设定回应的过期缓存TTL(秒)
serve-expired-reply-ttl 5
# 禁用IPV6
force-AAAA-SOA yes
# 强制指定 qtyp 返回 SOA
force-qtype-SOA 65