因为是虚拟机下使用,下载虚拟机专用的镜像
https://alpinelinux.org/downloads/ Virtual板块下载86_64镜像
当前 http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64/alpine-virt-3.12.1-x86_64.iso
创建虚拟机 当前alpine内核是5.4,虚拟机创建及初始化过程略过
apk update && apk upgrade && apk add sudo nano
下载并安装smartdns from https://github.com/pymumu/smartdns
cd /tmp wget https://github.com/pymumu/smartdns/releases/download/Release46.1/smartdns.1.2025.03.02-1533.x86_64-linux-all.tar.gz cn wget https://ghproxy.net/https://github.com/pymumu/smartdns/releases/download/Release46.1/smartdns.1.2025.03.02-1533.x86-linux-all.tar.gz tar xvf smartdns.1.2025.03.02-1533.x86-linux-all.tar.gz && cd smartdns && chmod +x ./install && mkdir mkdir /etc/default && ./install -i
rc-service smartdns stop
mv /etc/smartdns/smartdns.conf /etc/smartdns/smartdns.conf.bak nano /etc/smartdns/smartdns.conf server-name smartdns bind :53 bind-tcp :53 cache-size 1536 prefetch-domain yes serve-expired yes log-level info server-tls 208.67.222.222:853 #server-https https://dns.twnic.tw/dns-query server-tls 45.32.55.94:853 server-https https://cloudflare-dns.com/dns-query server-https https://neatdns.ustclug.org/resolve server-https https://doh.dns.sb/dns-query server-https https://public.dns.iij.jp/dns-query server-https https://dns.rubyfish.cn/dns-query server-https https://dns.dns-over-https.com/dns-query server-https https://jp.tiar.app/dns-query server-https https://i.233py.com/dns-query server 223.5.5.5:53 server 114.114.114.114:53 conf-file /tmp/whitelist.conf conf-file /tmp/blacklist.conf ipset /tracker.publicbt.com/block ipset /tracker.publicbt.com/b- address /tracker.publicbt.com/- address /publicbt.com/- address /www.publicbt.com/- address /*.publicbt.com/-
取消DHCP DNS自动覆盖
nano /usr/share/udhcpc/default.script 用#注释RESOLV_CONF="/etc/resolv.conf"
修改本地DNS为127.0.0.1
nano /etc/resolv.conf nameserver 127.0.0.1
启动smartdns并测试
/usr/sbin/smartdns 测试 nslookup -querytype=ptr smartdns
开机启动,默认的服务没法启动,未知
/usr/sbin/smartdns nano /etc/local.d/init_nextcloud.start #!/bin/sh /usr/sbin/smartdns chmod +x /etc/local.d/init_nextcloud.start rc-update add local
添加守护
apk add monit mv /etc/monitrc /etc/monitrc.bak nano /etc/monitrc set daemon 10 #10s循环监控 set logfile syslog check process smartdns with pidfile /var/run/smartdns.pid start program = "/usr/sbin/smartdns" with timeout 10 seconds stop program = "/usr/bin/killall smartdns" with timeout 10 seconds chmod 0700 /etc/monitrc 测试守护配置 monit -t 启动 rc-service monit start monit start all #忽略有个报错 添加启动 rc-update add monit
配置2
server-name smartdns # 监听53端口 - SmartDNS 将监听在端口 53 上处理 DNS 请求 #bind [::]:53 bind 0.0.0.0:53 # 启用双栈 IP 选择 - 允许 SmartDNS 根据网络状况选择 IPv4 或 IPv6 dualstack-ip-selection yes #https://toolb.cn/publicdns # 上游服务器配置 - 指定外部 DNS 服务器用于解析 # 114DNS - 国内常用公共 DNS,速度快且稳定 server 114.114.114.114 # 阿里公共 DNS - 国内广泛使用,解析速度快,支持防污染 server 223.6.6.6 # 腾讯公共 DNS - 国内大型厂商提供,稳定且安全 server 119.29.29.29 # 百度公共 DNS - 国内常用,适合多种网络环境 server 180.76.76.76 #清华大学TUNA协会DNS server 101.6.6.6 #CNNIC SDNS server 210.2.4.8 # 中国电信 广东 server 202.96.128.86 # 中国电信 江西 server 202.101.224.69 # 中国电信 上海 server 202.96.209.133 # 中国移动 江西 server 211.141.90.68 # 中国移动 广东 server 211.136.192.6 # 中国联通 广东 server 210.21.196.6 # 中国联通 上海 server 210.22.70.3 #广东广电 server 116.116.116.116 #华为 server 122.112.208.1 #360 server 101.226.4.6 #字节 server 180.184.1.1 # 启用过期缓存服务 - 在上游服务器未响应时提供过期缓存 serve-expired yes # 过期缓存的最长保留时间 - 259200 秒 = 3 天 serve-expired-ttl 86400 # 过期缓存的响应 TTL - 3 秒 serve-expired-reply-ttl 3 # 启用域名预取 - 提前缓存常用域名,提高响应速度 prefetch-domain yes # 预取的时间间隔 - 21600 秒 = 6 小时 #serve-expired-prefetch-time 3600 # 缓存大小 - 设置 32768 条记录,适用于中大型网络环境 cache-size 16384 # 启用缓存持久化 - 重启后保留缓存数据 cache-persist yes # 缓存文件路径 - 用于存储持久化缓存 cache-file cache.file # 缓存检查点时间 - 86400 秒 = 1 天,定期保存缓存到文件 cache-checkpoint-time 86400 # 配置文件 - 加载额外的配置文件,例如广告拦截规则 conf-file anti-ad-smartdns.conf