用alpine基于smartdns建立本地DNS服务器

因为是虚拟机下使用,下载虚拟机专用的镜像

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

 

wget https://github.com/pymumu/smartdns/releases/download/Release33/smartdns.1.2020.09.08-2235.x86_64-linux-all.tar.gz
tar xvf smartdns.1.2020.09.08-2235.x86_64-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

发表回复