目的:缓存dns加速网络传输
安装:
#yum -y install dnsmasq
配置:
1、#vi /etc/dnsmasq.conf
找到
#resolv-file=
修改为
resolv-file=/etc/resolv.dnsmasq.conf
2、配置好/etc/resolv.conf文件,如我的dns服务器ip是。8.8.8.8,那么我的加入下面一行。
nameserver 8.8.8.8
3、#cp /etc/resolv.conf /etc/resolv.dnsmasq.conf
4、#echo 'nameserver 127.0.0.1' > /etc/resolv.conf
5、#/etc/init.d/dnsmasq restart
测试:
#dig www.163.com
; <<>> DiG 9.7.0-P2-RedHat-9.7.0-5.P2.el6 <<>> www.163.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61904
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.163.com. IN A
;; ANSWER SECTION:
www.163.com. 520 IN CNAME www.cache.wangsu.netease.com.
www.cache.wangsu.netease.com. 520 IN CNAME www.163.com.lxdns.com.
www.163.com.lxdns.com. 3520 IN CNAME www.163.z.lxdns.com.
www.163.z.lxdns.com. 520 IN CNAME 163.xdwscache.glb0.lxdns.com.
163.xdwscache.glb0.lxdns.com. 40 IN A 222.88.93.137
163.xdwscache.glb0.lxdns.com. 40 IN A 222.88.93.169
;; Query time: 34 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Apr 22 16:07:00 2011
;; MSG SIZE rcvd: 189
第一次dns解析34毫秒
再来一次
#dig www.163.com
; <<>> DiG 9.7.0-P2-RedHat-9.7.0-5.P2.el6 <<>> www.163.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56506
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.163.com. IN A
;; ANSWER SECTION:
www.163.com. 536 IN CNAME www.cache.wangsu.netease.com.
www.cache.wangsu.netease.com. 536 IN CNAME www.163.com.lxdns.com.
www.163.com.lxdns.com. 3536 IN CNAME www.163.z.lxdns.com.
www.163.z.lxdns.com. 536 IN CNAME 163.xdwscache.glb0.lxdns.com.
163.xdwscache.glb0.lxdns.com. 56 IN A 222.88.93.137
163.xdwscache.glb0.lxdns.com. 56 IN A 222.88.93.169
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Apr 22 16:08:55 2011
;; MSG SIZE rcvd: 213
dns解析变成0了。
本文转自yuangang_love 51CTO博客,原文链接:http://blog.51cto.com/linux008/551372,如需转载请自行联系原作者