Lxn-Chan!

(~ ̄▽ ̄)→))* ̄▽ ̄*)o

使用 smartdns 做到对域名进行分区解析。

1. 确定需求

首先获取smartdns,可以使用官方安装源,也可以使用官方GitHub的静态编译版本,我这里采用后者。

我这里是有两条上行,分流规则是按照国内和非国内的IP地址进行分流。因此我这里需要做的就是国内的网站解析为国内的IP、其他域名走海外解析。

首先先创建4个文件:smartdns-audit.logsmartdns.cachesmartdns.confsmartdns.log,然后打开smartdns.conf进行配置。

2. 基本配置

这一步基本是很简单的基本配置,大多数场景只需要按照下面配置即可。

服务端配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 绑定端口,我这里只绑定了IPv4
bind :53
# 自动调整缓存大小
cache-size -1
# 缓存持久化
cache-persist yes
# 持久化保存位置
cache-file /root/smartdns/smartdns.cache
# 多久写入一次文件
cache-checkpoint-time 3600
# Smartdns可以设置缓存预获取,避免缓存超时,配置预先获取后,smartdns将在域名超时前的5s内,重新进行域名查询。并对域名的热度进行排序。
prefetch-domain yes
# 不解析IPv6结果
force-AAAA-SOA yes
# 最多给客户端返回几个解析结果
max-reply-ip-num 3
# 请求限制,0为不限制
max-query-limit 0

日志与审计

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 日志级别
log-level info
# 日志位置
log-file /root/smartdns/smartdns.log
# 单个日志文件上限
log-size 1m
# 保存的日志数量
log-num 999

# 审计开关
audit-enable yes
# 审计文件位置
audit-file /root/smartdns/smartdns-audit.log
# 单个审计文件上限
audit-size 1m
# 保存的审计文件数量
audit-num 999

3. 国内域名解析

首先先选定几个DNS服务器用于解析国内域名,我这里选择了腾讯云DNSPod和阿里云DNS,形成china组,不参与默认解析。

1
2
3
4
server 119.29.29.29 -group china -exclude-default-group
server 223.5.5.5 -group china -exclude-default-group
server 119.28.28.28 -group china -exclude-default-group
server 223.6.6.6 -group china -exclude-default-group

然后clone仓库:

1
git clone https://github.com/felixonmars/dnsmasq-china-list && cd dnsmasq-china-list

进去指定smartdns并进行make,SERVER字段指定解析这些国内域名的组名:

1
make smartdns SERVER=china

然后将配置引入smartdns的配置文件即可:

1
2
3
4
conf-file /root/smartdns/dnsmasq-china-list/accelerated-domains.china.smartdns.conf
conf-file /root/smartdns/dnsmasq-china-list/bogus-nxdomain.china.smartdns.conf
conf-file /root/smartdns/dnsmasq-china-list/apple.china.smartdns.conf
conf-file /root/smartdns/dnsmasq-china-list/google.china.smartdns.conf

4. 非国内域名解析

这部分相对就简单了,基本就是指定服务器然后写成一组就行。我这里怕有污染所以单独给DoT和DoH的域名加了-bootstrap-dns用于解析他们自己。

1
2
3
4
5
6
7
8
9
10
11
12
server 8.8.8.8 -group foreign
server 8.8.4.4 -group foreign
server 4.2.2.2 -group foreign
server 4.2.2.5 -group foreign
server 1.0.0.1 -group foreign
server 64.6.64.6 -group foreign
server 64.6.65.6 -group foreign
server-tls 1dot1dot1dot1.cloudflare-dns.com -group foreign -bootstrap-dns 1.0.0.1 -bootstrap-dns 9.9.9.9
server-https https://dns.google/dns-query -group foreign -bootstrap-dns 8.8.8.8 -bootstrap-dns 9.9.9.9
server-https https://cloudflare-dns.com/dns-query -group foreign -bootstrap-dns 1.0.0.1 -bootstrap-dns 9.9.9.9
server-https https://dns.quad9.net/dns-query -group foreign -bootstrap-dns 9.9.9.9 -bootstrap-dns 8.8.8.8
server-https https://dns9.quad9.net/dns-query -group foreign -bootstrap-dns 9.9.9.9 -bootstrap-dns 8.8.8.8

5. 使用systemd启动smartdns

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[Unit]
Description=SmartDNS Server
After=network.target
Before=network-online.target
Before=nss-lookup.target
Wants=nss-lookup.target
StartLimitBurst=0
StartLimitIntervalSec=60

[Service]
Type=forking
PIDFile=/var/run/smartdns.pid
ExecStart=/root/smartdns/smartdns-x86_64 -p /var/run/smartdns.pid -c /root/smartdns/smartdns.conf
Restart=always
RestartSec=2
TimeoutStopSec=15

[Install]
WantedBy=multi-user.target
Alias=smartdns.service

6. China-List自动更新

哎呀反正就是把gitmake写进crontab然后你懂的,不懂问AI。懒得写了。

 简单说两句



联系站长 | 服务状态 | 友情链接

备案号:辽ICP备19013963号

津公网安备12011602300394号

中国互联网违法和不良信息举报中心

架构版本号:8.1.7 | 本站已全面支持IPv6

正在载入运行数据(1/2)请稍后...
正在载入运行数据(2/2)请稍后...

♥stand with innovative technologies of all kinds♥

Copyright 2024 LingXuanNing, All rights reserved.