centos安装chinadns

jimmy 2018年03月11日 3,823次浏览

首先安装git客户端

[root@localhost ~]#yum -y install git

已安装:
  git.x86_64 0:1.8.3.1-12.el7_4                                                                               

作为依赖被安装:
  libgnome-keyring.x86_64 0:3.12.0-1.el7 perl-Error.noarch 1:0.17020-2.el7 perl-Git.noarch 0:1.8.3.1-12.el7_4
  perl-TermReadKey.x86_64 0:2.30-20.el7  rsync.x86_64 0:3.0.9-18.el7      

完毕!

出现以上提示表示安装成功。

下载chinadns

[root@localhost ~]# git clone https://github.com/shadowsocks/ChinaDNS.git
正克隆到 \'ChinaDNS\'...
remote: Counting objects: 833, done.
remote: Total 833 (delta 0), reused 0 (delta 0), pack-reused 833
接收对象中: 100% (833/833), 180.40 KiB | 7.00 KiB/s, done.
处理 delta 中: 100% (428/428), done.

#开始安装

[root@localhost ChinaDNS]# yum -y install automake
[root@localhost ChinaDNS]# yum -y install gcc
[root@localhost ChinaDNS]# ./autogen.sh 
[root@localhost ChinaDNS]#  ./configure 
[root@localhost ChinaDNS]# make
[root@localhost src]# pwd
/root/ChinaDNS/src
[root@localhost src]# ./chinadns -h
usage: chinadns [-h] [-l IPLIST_FILE] [-b BIND_ADDR] [-p BIND_PORT]
       [-c CHNROUTE_FILE] [-s DNS] [-m] [-v] [-V]
Forward DNS requests.

  -l IPLIST_FILE        path to ip blacklist file
  -c CHNROUTE_FILE      path to china route file
                        if not specified, CHNRoute will be turned
  -d                    off enable bi-directional CHNRoute filter
  -y                    delay time for suspects, default: 0.3
  -b BIND_ADDR          address that listens, default: 0.0.0.0
  -p BIND_PORT          port that listens, default: 53
  -s DNS                DNS servers to use, default:
                        114.114.114.114,208.67.222.222:443,8.8.8.8
  -m                    use DNS compression pointer mutation
                        (backlist and delaying would be disabled)
  -v                    verbose logging
  -h                    show this help message and exit
  -V                    print version and exit

Online help: <https://github.com/clowwindy/ChinaDNS>

测试

[root@localhost src]# yum -y install net-utils
[root@localhost src]# ./chinadns -v -c ../chnroute.txt 
Sun Mar 11 21:54:27 2018 request twitter.com
Sun Mar 11 21:54:27 2018 response twitter.com from 114.114.114.114:53 - 104.244.42.193, filter
Sun Mar 11 21:54:27 2018 response twitter.com from 8.8.8.8:53 - 104.244.42.65, 104.244.42.193, pass
Sun Mar 11 21:54:27 2018 response twitter.com from 8.8.4.4:53 - 104.244.42.193, 104.244.42.65, pass
Sun Mar 11 21:54:27 2018 response twitter.com from 208.67.222.222:5353 - 104.244.42.65, 104.244.42.193, pass
Sun Mar 11 21:54:27 2018 response twitter.com from 208.67.222.222:443 - 104.244.42.65, 104.244.42.1, pass
重新打开一个窗口执行下面的命令才会输出上面的日志
[root@localhost yum.repos.d]# dig twitter.com @localhost

; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7_4.2 <<>> twitter.com @localhost
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26055
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;twitter.com.			IN	A

;; ANSWER SECTION:
twitter.com.		1249	IN	A	104.244.42.65
twitter.com.		1249	IN	A	104.244.42.193

;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: 日 3月 11 21:54:27 CST 2018
;; MSG SIZE  rcvd: 72

结束

注意返回的IP可能是被XX了,要得到正确的地址需要走特别的线路。

    curl \'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest\' | grep ipv4 | grep CN | awk -F\\| \'{ printf("%s/%d\\n", $4, 32-log($5)/log(2)) }\' > chnroute.txt