SmartDNS是推荐本地运行的DNS服务器,SmartDNS接受本地客户端的DNS查询请求,从多个上游DNS服务器获取DNS查询结果,并将访问速度最快的结果返回给客户端,提高网络访问速度和准确性。 支持指定域名IP地址,达到禁止过滤的效果。
一 安装smartdns
1 关闭Ubuntu自带dns解析systemd-resolved
- #查看端口
- sudo netstat -lnp|grep 53
- tcp 0 0 127.0.0.54:53 0.0.0.0:* LISTEN 698/systemd-resolve
- tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 698/systemd-resolve
- udp 0 0 127.0.0.54:53 0.0.0.0:* 698/systemd-resolve
- udp 0 0 127.0.0.53:53 0.0.0.0:* 698/systemd-resolve
- raw6 0 0 :::58 :::* 7 553/systemd-network
- unix 2 [ ACC ] STREAM LISTENING 9453 924/systemd /run/user/1000/pk-debconf-socket
- #关闭
- sudo systemctl disable systemd-resolved
- sudo systemctl stop systemd-resolved
2 安装 smartdns
- sudo apt update
- sudo apt-get install smartdns
- #查看版本
- test@test:~$ smartdns -v
- smartdns 45+dfsg-1build2
- #启动
- sudo systemctl enable smartdns
- sudo systemctl start smartdns
二 配置smartdns
- sudo vim /etc/smartdns/smartdns.conf
- #接口绑定信息
- bind-tcp [::]:53
- bind :53
- #开启过期缓存
- serve-expired yes
- #过期时间
- serve-expired-ttl 0
- #缓存数量
- cache-size 68888
- #域名TTL最小值和最大值
- rr-ttl-min 60
- rr-ttl-max 866000
- # 上游DNS返回多个结果时,测速的方法
- speed-check-mode tcp:80,tcp:443,ping
- #日志记录等级(warn,info,debug)
- log-level info
- log-file /var/log/smartdns/smartdns.log
- log-size 2m #日志大小
- log-num 1 #日志归档个数
- #配置上游dns服务器
- #阿里dns
- server 223.5.5.5
- server 223.6.6.6
- #腾讯dns
- server 119.29.29.29
- #配置server的组关系
- server 8.8.8.8 -group google -exclude-default-group
- server 8.8.4.4 -group whatsappdns -exclude-default-group
- server-tcp 8.8.4.4
- #配置address,解析指定的域名和IP
- address /www.test.com/192.168.50.13
三 测试验证
1 ubuntu 系统
- #第一次查询
- test@test:~$ dig www.csdn.net
-
- ; <<>> DiG 9.18.24-0ubuntu5-Ubuntu <<>> www.csdn.net
- ;; global options: +cmd
- ;; Got answer:
- ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32569
- ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
-
- ;; QUESTION SECTION:
- ;www.csdn.net. IN A
-
- ;; ANSWER SECTION:
- www.csdn.net. 3 IN CNAME 55cb88f4.csdn.net.cname.yunduns.com.
- 55cb88f4.csdn.net.cname.yunduns.com. 3 IN A 220.185.184.18
-
- ;; Query time: 532 msec
- ;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
- ;; WHEN: Sat Jun 01 17:45:37 CST 2024
- ;; MSG SIZE rcvd: 95
-
- #第二次查询
- test@test:~$ dig www.csdn.net
-
- ; <<>> DiG 9.18.24-0ubuntu5-Ubuntu <<>> www.csdn.net
- ;; global options: +cmd
- ;; Got answer:
- ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36998
- ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
-
- ;; QUESTION SECTION:
- ;www.csdn.net. IN A
-
- ;; ANSWER SECTION:
- www.csdn.net. 32 IN CNAME 55cb88f4.csdn.net.cname.yunduns.com.
- 55cb88f4.csdn.net.cname.yunduns.com. 32 IN A 220.185.184.18
-
- ;; Query time: 0 msec
- ;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
- ;; WHEN: Sat Jun 01 17:46:05 CST 2024
- ;; MSG SIZE rcvd: 95
- #测试域名查询
- test@test:~$ dig www.test.com
-
- ; <<>> DiG 9.18.24-0ubuntu5-Ubuntu <<>> www.test.com
- ;; global options: +cmd
- ;; Got answer:
- ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41058
- ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
-
- ;; QUESTION SECTION:
- ;www.test.com. IN A
-
- ;; ANSWER SECTION:
- www.test.com. 60 IN A 192.168.50.13
-
- ;; Query time: 0 msec
- ;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
- ;; WHEN: Sat Jun 01 17:49:50 CST 2024
- ;; MSG SIZE rcvd: 46
2 windoes 11系统