银鞍照白马, 飒沓如流星

使用 iOS 快捷指令管理 SmartDNS

    network

  1. 出发点
  2. 解决方案
  3. 操作界面
  4. 总结

之前网络布局使用了 SmartDNS 作为 DNS 服务,并承担分流能力。但是 smartDNS 并不提供管理界面,每次添加新的域名都需要手动修改配置文件,十分麻烦。于是我写了一个小服务,并通过 iOS 快捷指令来进行管理。

出发点

在蹲坑的某天,突然发现有个网站打不开,怀疑域名是被墙了,但如果想把这个域名加入到翻墙列表里,要么修改 smartDNS 的配置,加到 GFWList 里,要么修改 clash 配置,加到 rule 里。但这两个方式都得打开电脑,登录到 gateway 服务器上修改。这种方式实在是太不 geek 了。

解决方案

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
server-name gateway
bind []:53
cache-size 2048
log-level info
log-file /var/log/smartdns.log
user root

# include-conf
conf-file accelerated-domains.china.smartdns.conf
conf-file apple.china.smartdns.conf
conf-file google.china.smartdns.conf
conf-file gfw.domain.smartdns.conf

# domain-set
domain-set -name white -type list -file white.smartdns.conf
nameserver /domain-set:white/china
domain-set -name blacklist -type list -file blacklist.smartdns.conf
nameserver /domain-set:blacklist/GFW
domain-set -name ad -type list -file ad.smartdns.conf
address /domain-set:ad/#

# upstream
server 127.0.0.1:7853 -group GFW -exclude-default-group
server 8.8.8.8
server-https https://1.1.1.1/dns-query
server 223.5.5.5 -group china -exclude-default-group
server-https https://dns.alidns.com/dns-query -group china -exclude-default-group

根据 smartDNS 配置,可以看到,smartDNS 的配置文件分为三部分,include-confdomain-setupstream。其中include-conf是引入其他配置文件,domain-set是定义域名集合,upstream是定义上游 DNS 服务器。 include-conf 都是使用的共享配置,只需要定期更新就可以了。
这样只需要定义upstreamdomain-set,就可以很重新生成smartdns.conf,然后重启 smartDNS 服务,就可以实现添加域名的功能了。

为了实现简单和部署方便,使用golang进行开发,gin暴露 http 接口,gorm + sqlite3存储数据,template输出配置文件,coreos/go-systemd重新加载服务。简单组合一下,一个简单的 smartDNS 的管理服务就完成了。

project

操作界面

写完服务接口,突然不像写前端页面,于是就想到了 iOS 快捷指令,可以通过快捷指令来调用接口,实现添加域名的功能。于是就有了下面的操作界面。

short cut

总结

虽然快捷指令受限与 API 操作不是非常灵活,但是对于简单的操作还是非常方便的。而且可以通过快捷指令来调用接口,实现一些简单的功能,也是非常有意思的。

page PV:  ・  site PV:  ・  site UV: