dnsmasq

目录

dnsmasq


  如果在服务器上的程序需要访问别的网站,如果要经过 dns 服务器区去访问就会很慢。解决方案是在本机做一个 dns 的缓存,可以使用 dnsmasq 来做。


安装

#Centso
yum install dnsmasq

配置

cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
echo "resolv-file=/etc/resolv.dnsmasq.conf" >>/etc/dnsmasq.conf
cp /etc/resolv.conf /etc/resolv.dnsmasq.conf
echo "nameserver 127.0.0.1" > /etc/resolv.conf
chkconfig dnsmasq on;service dnsmasq start

启动

chkconfig dnsmasq on;service dnsmasq start

用 dig 命令测试看是否有效

第一次可以看到查询还是需要时间的
[root@10-6-13-97 ~]# dig www.jd.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> www.jd.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27431
;; flags: qr rd ra; QUERY: 1, ANSWER: 7, AUTHORITY: 0, ADDITIONAL: 0

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

;; ANSWER SECTION:
www.jd.com.             1784    IN      CNAME   www.jdcdn.com.
www.jdcdn.com.          284     IN      A       60.28.204.152
www.jdcdn.com.          284     IN      A       60.28.204.156
www.jdcdn.com.          284     IN      A       60.28.204.151
www.jdcdn.com.          284     IN      A       60.28.204.153
www.jdcdn.com.          284     IN      A       60.28.204.154
www.jdcdn.com.          284     IN      A       60.28.204.155

;; Query time: 46 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri May 30 15:28:37 2014
;; MSG SIZE  rcvd: 148

第二次就可以看出已经缓存了
[root@10-6-13-97 ~]# dig www.jd.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> www.jd.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8177
;; flags: qr rd ra; QUERY: 1, ANSWER: 7, AUTHORITY: 0, ADDITIONAL: 0

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

;; ANSWER SECTION:
www.jd.com.             1769    IN      CNAME   www.jdcdn.com.
www.jdcdn.com.          269     IN      A       60.28.204.155
www.jdcdn.com.          269     IN      A       60.28.204.154
www.jdcdn.com.          269     IN      A       60.28.204.153
www.jdcdn.com.          269     IN      A       60.28.204.151
www.jdcdn.com.          269     IN      A       60.28.204.156
www.jdcdn.com.          269     IN      A       60.28.204.152

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri May 30 15:28:52 2014
;; MSG SIZE  rcvd: 151



目录