
| dualstack-ip-selection
no serve-expired yes cache-size 8192 dnsmasq-lease-file /tmp/dhcp.leases odhcpd-lease-file /tmp/odhcpd.leases rr-ttl-min 600 log-size 64K log-num 1 log-level info log-syslog yes audit-size 64K audit-num 1 response-mode first-ping cache-persist yes cache-file /etc/smartdns/smartdns.cache resolv-file /tmp/resolv.conf.d/resolv.conf.auto bind :5353@br-lan bind :5353@lo bind-tcp :5353@br-lan bind-tcp :5353@lo bind-https :843@br-lan bind-https :843@lo bind-cert-generate yes bind-cert-root-key-file /etc/smartdns/smartdns-root-key.pem bind-cert-file /etc/smartdns/smartdns-cert.pem bind-cert-key-file /etc/smartdns/smartdns-key.pem server-https https://ram.kicsm.kdns.fr/ramdo server-h3 https://wan.legenws.kdns.fr/disco server-h3 https://tem.tech.kdns.fr/impro server-https https://dbase.txtdb.kdns.fr/tisks 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 |
| dualstack-ip-selection
no serve-expired yes cache-size 8192 dnsmasq-lease-file /tmp/dhcp.leases odhcpd-lease-file /tmp/odhcpd.leases rr-ttl-min 600 log-size 64K log-num 1 log-level info log-syslog yes audit-size 64K audit-num 1 response-mode first-ping cache-persist yes cache-file /etc/smartdns/smartdns.cache resolv-file /tmp/resolv.conf.d/resolv.conf.auto bind :5353@br-lan bind :5353@lo bind-tcp :5353@br-lan bind-tcp :5353@lo bind-https :843@br-lan bind-https :843@lo bind-cert-generate yes bind-cert-root-key-file /etc/smartdns/smartdns-root-key.pem bind-cert-file /etc/smartdns/smartdns-cert.pem bind-cert-key-file /etc/smartdns/smartdns-key.pem 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 |
mkdir -p /etc/smartdns/upstreams
# bootstrap(解析 DoH 域名用,不要删)
server 223.5.5.5 -bootstrap-dns
server 119.29.29.29 -bootstrap-dns
server-https https://ram.kicsm.kdns.fr/ramdo
server-https https://trems.chem.kdns.fr/plat
server-https https://bin.factory.kdns.fr/link
server-https https://12.footeam.kdns.fr/teamai
server 223.5.5.5 -bootstrap-dns
server 119.29.29.29 -bootstrap-dns
server-https https://cook.cakemu.kdns.fr/technol
server-https https://bar2000.foobarl.kdns.fr/teamma
server-https https://paper.dinner.kdns.fr/linkto
server-https https://toos.reflash.kdns.fr/addon
server 223.5.5.5 -bootstrap-dns
server 119.29.29.29 -bootstrap-dns
server-https https://quess.kato.kdns.fr/temp
server-https https://mus.musiclyric.kdns.fr/lyrics
server-https https://testadd.igure.kdns.fr/cookies
server-https https://cacl.shoes.kdns.fr/for
server 223.5.5.5 -bootstrap-dns
server 119.29.29.29 -bootstrap-dns
server-https https://account.temple.kdns.fr/andaa
server-https https://name.protech.kdns.fr/nomane
server-https https://example.winnis.kdns.fr/mem
server-https https://tis.forten.kdns.fr/moddi
server 223.5.5.5 -bootstrap-dns
server 119.29.29.29 -bootstrap-dns
server-https https://no.fourth.kdns.fr/four
server-https https://for.istwo.kdns.fr/fine
server-https https://tree.transtwo.kdns.fr/four
server-https https://tradedb01.20162000.xyz/saledb
cp /etc/smartdns/upstreams/batch1. /etc/smartdns/active_upstream.
echo 0 > /etc/smartdns/rotate_state
编 辑 /etc/smartdns/custom.,只保留或追加这一行(不 要重复写上游):
-file /etc/smartdns/active_upstream.
如 果 custom. 里已有其它自定义规则,把上面这行加在文件末尾即可。
打 开你生成的主配置(通常在 /var/etc/smartdns/smartdns. 或 LuCI 对应位置),确认没有类似下面的行:
server-https https://....
server-h3 https://....
你
原来的监听、缓存、日志等保持不动,例如:
bind :5353@br-lan
bind :5353@lo
bind-tcp :5353@br-lan
bind-tcp :5353@lo
...
-file /etc/smartdns/address.
-file /etc/smartdns/blacklist-ip.
-file /etc/smartdns/custom.
创
建 /etc/smartdns/rotate_upstream.sh:
#!/bin/sh
UPSTREAM_DIR="/etc/smartdns/upstreams"
ACTIVE_="/etc/smartdns/active_upstream."
STATE_FILE="/etc/smartdns/rotate_state"
LOCK_FILE="/var/run/smartdns_rotate.lock"
# 防止并发
[ -f "$LOCK_FILE" ] && exit 0
touch "$LOCK_FILE"
trap "rm -f $LOCK_FILE" EXIT
BATCHES=$(ls "$UPSTREAM_DIR"/batch*. 2>/dev/null | sort)
if [ -z "$BATCHES" ]; then
logger -t smartdns-rotate "ERROR: no batch*. found in $UPSTREAM_DIR"
exit 1
fi
INDEX=0
[ -f "$STATE_FILE" ] && INDEX=$(cat "$STATE_FILE")
COUNT=$(echo "$BATCHES" | wc -l)
NEXT=$(( (INDEX + 1) % COUNT ))
TARGET=$(echo "$BATCHES" | sed -n "$((NEXT + 1))p")
cp "$TARGET" "$ACTIVE_"
echo "$NEXT" > "$STATE_FILE"
# 优先用 reload,失败再 restart
/etc/init.d/smartdns reload 2>/dev/null || /etc/init.d/smartdns restart
logger -t smartdns-rotate "Switched to $(basename "$TARGET") (index $NEXT / total $COUNT)"
赋
予执行权限:
chmod +x /etc/smartdns/rotate_upstream.sh
crontab -e
加
入:
0 */3 * * * /etc/smartdns/rotate_upstream.sh
保
存后:
/etc/init.d/cron restart
说 明:0 */3 * * * 表示每天 0 点、3 点、6 点、9 点、12 点、15 点、18 点、21 点执行。
# 1. 重新加载 SmartDNS
/etc/init.d/smartdns restart
# 2. 看当前用的是哪一组
cat /etc/smartdns/active_upstream.
# 3. 手动切换一次测试
/etc/smartdns/rotate_upstream.sh
cat /etc/smartdns/active_upstream.
logread | grep smartdns-rotate
# 4. 测试解析(按你实际监听端口)
nslookup www.baidu.com 127.0.0.1#5353
# 或
dig @127.0.0.1 -p 5353 www.baidu.com
/etc/smartdns/
├── address.
├── blacklist-ip.
├── custom. ← 里面有 -file active_upstream.
├── active_upstream. ← 当前生效的那一组(脚本会覆盖)
├── rotate_state ← 记录当前是第几组(0~4)
├── rotate_upstream.sh ← 轮换脚本
└── upstreams/
├── batch1.
├── batch2.
├── batch3.
├── batch4.
└── batch5.
想改用 HTTP/3
把对应行的 server-https 改成 server-h3 即可(前提是你的 SmartDNS 版本支持且 OpenSSL 够新)。
bootstrap 想换
可以把批次文件里的 223.5.5.5 / 119.29.29.29 换成你更信任的,例如:
server 1.1.1.1 -bootstrap-dns
server 8.8.8.8 -bootstrap-dns
临时固定某一组
cp /etc/smartdns/upstreams/batch3.conf /etc/smartdns/active_upstream.conf
echo 2 > /etc/smartdns/rotate_state
/etc/init.d/smartdns reload
暂停轮换
注释掉 crontab 那一行,或删掉即可。
按 上面做完后,SmartDNS 会在每 3 小时自动在 5 组上游之间循环切换。