配置文件

只涉及到分流的部分,其中默认(国外)的DOH解析服务器需要你所在地区可以正常访问

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# ------------------------------------国内------------------------------------

# 引入中国域名列表,使用 cn 组解析
conf-file /etc/smartdns/domain-set/cn.conf

# CN组服务器(上游DNS服务器)
server-https https://dns.alidns.com/dns-query -group cn -exclude-default-group
server-https https://doh.pub/dns-query -group cn -exclude-default-group

# Bootstrap DNS 服务器,用于解析cn组上游的 DoH 解析器的 IP 地址
server 223.6.6.6 -group alidns -exclude-default-group
server 223.5.5.5 -group alidns -exclude-default-group
server 119.29.29.29 -group dnspod -exclude-default-group
server 119.28.28.28 -group dnspod -exclude-default-group

# 为上游的 DoH 解析器指定 Bootstrap DNS 服务器
nameserver /alidns.com/alidns
nameserver /doh.pub/dnspod

# -------------------------默认(国外),使用国外DNS解析-------------------------

# Bootstrap DNS 服务器,用于解析指定为上游的 DoH 解析器的 IP 地址
server 8.8.8.8 -group google -exclude-default-group
server 8.8.4.4 -group google -exclude-default-group
server 1.1.1.1 -group cloudflare -exclude-default-group
server 1.0.0.1 -group cloudflare -exclude-default-group
server 9.9.9.9 -group quad9 -exclude-default-group
server 208.67.222.222 -group opendns -exclude-default-group

# 用来解析默认(国外)域名的上游 DoH 解析器
nameserver /dns.google/google
nameserver /quad9.net/quad9
nameserver /opendns.com/opendns
nameserver /cloudflare-dns.com/cloudflare

# 为上游的 DoH 解析器指定 Bootstrap DNS 服务器
server-https https://dns.google/dns-query
server-https https://dns.quad9.net/dns-query
server-https https://doh.opendns.com/dns-query
server-https https://cloudflare-dns.com/dns-query

引入中国域名列表

创建一个脚本 rules.sh

获取最新的配置文件,需要你所在的网络可以正常下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh

echo $(date)
# 检查文件是否存在,如果存在则备份文件
if [ -f /etc/smartdns/domain-set/cn.conf ]; then
mv /etc/smartdns/domain-set/cn.conf /etc/smartdns/domain-set/cn.conf.bak
fi

echo "获取最新配置文件"
if curl -sSf "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/direct-list.txt" >> /etc/smartdns/domain-set/cn.conf &&
curl -sSf "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/apple-cn.txt" >> /etc/smartdns/domain-set/cn.conf &&
curl -sSf "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/google-cn.txt" >> /etc/smartdns/domain-set/cn.conf &&
sed "s/^full://g;s/^regexp:.*$//g;s/^/nameserver \//g;s/$/\/cn/g" -i /etc/smartdns/domain-set/cn.conf
then
echo "删除旧的备份文件"
if [ -f /etc/smartdns/domain-set/cn.conf.bak ]; then
rm /etc/smartdns/domain-set/cn.conf.bak
fi

echo "重载配置文件"
if service smartdns reload; then
echo "Smartdns:规则更新成功"
else
echo "Smartdns:重载失败"
exit 1
fi

else
if [ -f /etc/smartdns/domain-set/cn.conf.bak ]; then
mv /etc/smartdns/domain-set/cn.conf.bak /etc/smartdns/domain-set/cn.conf
fi
echo "下载配置文件失败,已恢复旧配置文件"
fi

定时任务

每天的凌晨4点自动更新配置文件,每周1自动删除之前的升级日志

1
2
0 4 * * * /etc/smartdns/rules.sh >> /etc/smartdns/update.log
0 5 * * 1 rm -rf /etc/smartdns/update.log