/ DNS

配置一只从DNS

因为黑宽带需求(主要是给隔壁老王开了个只有电信+移动的网关)和节约香港出口的流量(CN2出去的现在也是越来越不靠谱了,与此同时老爸竟然没事会看youtube)
闲来无事配了一台基于host翻墙的从DNS,配置情况如下:

  • Ubuntu 16.04  2Core/1G/20G
  • Dnsmasq
  • hosts - racaljk/hosts
  • dnsmasq-china-list - felixonmars/dnsmasq-china-list
  • 其他
    • dnsmasq 上游用 8.8.4.4,这台DNS的出口是走香港的
    • 引流视频站、晚上电信访问爆炸的站点到移动出口
    • DNS请求记录监控,没事上去看看调调解析

一只Ubuntu

先在家里虚拟机上起了一只Ubuntu 16.04 标准套路如下:

跪舔中科大镜像源 https://mirrors.ustc.edu.cn/repogen/

ubuntu开局(话说这个应该在做虚拟机模板的时候做好 =.=!!)

apt-get install build-essential git zsh
最后默默加上自己电脑的key,密码登录能没有就没有。

准备好需要的文件

切到你觉得舒服的文件夹下面
git clone https://github.com/felixonmars/dnsmasq-china-list.git git clone https://github.com/racaljk/hosts.git
用clone下来的hosts更新本机hosts
先到racaljk/hosts目录下面 sudo cat ./hosts >> /etc/hosts
在accelerated-domains.china.conf里修改一点你想修改的东西,比如随便加几行
#CMCC server=/10086.cn/211.140.188.188 server=/acgvideo.com/211.140.188.188 server=/bilibili.com/211.140.188.188 server=/bilibili.tv/211.140.188.188 server=/hdslb.com/211.140.188.188 server=/hdslb.net/211.140.188.188 server=/ykimg.com/211.140.188.188 server=/youku.com/211.140.188.188

安装Dnsmasq

一键安装妥妥的
apt-get install dnsmasq
然后编辑一下配置文件
vim /etc/dnsmasq.conf
取消注释并且修改 或者 备份/etc/dnsmasq.conf配置文件,把下面的配置写进去
port=53 server=8.8.4.4 listen-address=<这台机器的IP>,127.0.0.1 conf-file=<你舒服的文件夹>/dnsmasq-china-list/accelerated-domains.china.conf
最后重启dnsmasq服务
sudo service dnsmasq restart
试试看效果怎么样(开始疯狂凑字数)
$ dig www.google.com.hk @127.0.0.1

; <<>> DiG 9.10.3-P4-Ubuntu <<>> www.google.com.hk @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18033
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1280
;; QUESTION SECTION:
;www.google.com.hk. IN A

;; ANSWER SECTION:
www.google.com.hk. 0 IN A 61.91.161.217

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Feb 10 23:35:04 CST 2017
;; MSG SIZE rcvd: 62

$ dig www.baidu.com @127.0.0.1

; <<>> DiG 9.10.3-P4-Ubuntu <<>> www.baidu.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59494
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

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

;; ANSWER SECTION:
www.baidu.com. 982 IN CNAME www.a.shifen.com.
www.a.shifen.com. 35 IN A 115.239.211.112
www.a.shifen.com. 35 IN A 115.239.210.27

;; Query time: 12 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Feb 10 23:37:02 CST 2017
;; MSG SIZE rcvd: 101

$ dig www.bilibili.com @127.0.0.1

; <<>> DiG 9.10.3-P4-Ubuntu <<>> www.bilibili.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3453
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.bilibili.com. IN A

;; ANSWER SECTION:
www.bilibili.com. 600 IN CNAME bilibili.hdslb.net.
bilibili.hdslb.net. 600 IN A 112.25.253.7

;; Query time: 5 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Feb 10 23:40:20 CST 2017
;; MSG SIZE rcvd: 82

收工

记得修改DHCP Server发出去的DNS服务器哟 ^.^