简介
什么叫无污染DNS,这里按自己的理解说一下,我们一般访问网站,第一步是我们输入域名,例如输入baidu.com,这个域名只是方便记忆的一种形式,网络访问其实都是要访问到具体的IP,IP就是存放网页的服务器地址,那么我们输入baidu.com的IP是多少呢,就是由DNS服务器告诉我们的。现在一些国外网站如谷歌访问不了,就是因为DNS服务器告诉了我们一个错误的IP,这个IP要能根本就不存在,所以我们就访问不了我们需要访问的网站了,同时有一些DNS的服务商还会对你访问的网址进行劫持,例如,我们文章taobao.com,服务商的系统检测到会自动加上他们淘宝客的推广网站,这样你买东西时候会给他产生这一些佣金,这样我们不轻意之间就别一些垃圾商家利用,所以今天介绍的就是自己搭建一个干净的污染DNS。
准备工作
1、一台服务器或是VPS(我用的是阿里云的ECS)
2、安装Ubuntu 16.04 x64 纯净系统
3、使用项目为ChinaDNS 地址:GITHUB
注意:机器必须放在国内,否则是没有作用的。
搭建教程开始
下载脚本并编译
1
2
3
4
|
wget –no-check-certificate https://github.com/shadowsocks/ChinaDNS/releases/download/1.3.2/chinadns-1.3.2.tar.gz
tar -zxvf chinadns-1.3.2.tar.gz
cd chinadns-1.3.2
./configure && make
|
更新 CHNRouter
1
|
curl ‘http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | grep ipv4 | grep CN | awk -F| ‘{ printf(“%s/%dn”, $4, 32-log($5)/log(2)) }' > chnroute.txt
|
启动ChinaDNS并测试
1
|
./src/chinadns -m -c chnroute.txt -s 119.29.29.29,208.67.220.222:443
|
这里我使用的是国内DNSPod,国外OpenDNS,可以自行更改,注意国外DNS不能通过UDP53查询。
正常启动后不会输出任何信息,请使用nslookup或访问 http://tool.chinaz.com/dns/?type=1&host=steamcommunity.com&ip=VPS的IP地址 查看是否正确解析
守护运行
安装与配置
1
2
3
4
5
6
7
|
apt-get install supervisor #安装supervisor
echo_supervisord_conf > /etc/supervisord.conf
echo “[program:chinadns]
command=(运行ChinaDNS的指令,注意需要绝对路径,例如:/root/chinadns-1.3.2/src/chinadns -m -c chnroute.txt -s 119.29.29.29,208.67.220.222:443)
user = root
autostart = true
autorestart = true” >> /etc/supervisord.conf
|
使supervisor开机自启动,编辑 /etc/rc.local
1
|
vi /etc/rc.local
|
将 supervisord -c /etc/supervisord.conf 加入 exit 0 之前,编辑后的 rc.local 如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0” on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
supervisord -c /etc/supervisord.conf
exit 0
~
~
~
~
|
为rc.local增加权限
1
|
chmod +x /etc/rc.local
|
启动 supervisor
1
|
supervisord -c /etc/supervisord.conf
|
查看chinadns运行状态
1
|
supervisorctl status|grep “chinadns”
|
如果显示 RUNNING 即为成功,可以使用nslookup等方式确认是否正常运作。