Linux Fedora Dnsmasq 配置

来源:互联网 发布:淘宝上的药可以买吗 编辑:程序博客网 时间:2024/05/05 08:43

  1、前言

     测试系统需要频繁的去ping 外网资源,基本是各大网站,在并发量大的情况下,经常出现DNS解析不成功的问题。并且,使用分析工具查看很大一部分时间是消耗在DNS 解析上面。第一次解析成功,后面相同的操作就不用再DNS上面在耗费时间。所有考虑到使用DNS缓存服务。Linux 还跟windows 有区别,好像windows下面本身就开启了DNS缓存。

 

    2、Dnsmasq

 

     dnsmasq是一个 DNS缓存软件,但它同时也可以作为一个dns查询服务器,虽然不如bind等完善,但基本功能也够用了。

 

    3、Dnsmasq 配置

  • 配置 resolv.conf

         [root@TestAgent009 ~]# vi /etc/resolv.conf

         nameserver 127.0.0.1 //增加部分


         nameserver 218.30.19.50 //公网DNS
         nameserver 61.134.1.5    //公网DNS

  • 配置 dnsmasq.conf

         [root@TestAgent009 ~]# vi /etc/dnsmasq.conf

         resolv-file=/etc/dnsmasq.resolv.conf  //目前这个文件不存在,后面会说明拷贝

           listen-address=127.0.0.1

           addn-hosts=/etc/dnsmasq.hosts  //目前这个文件不存在,后面会说明拷贝

 

           需要修改的地方就是这三处。dnsmasq.conf 比较长,在 vi 可以使用 " / ",来查找resolv-file,  listen等关键字

  • 拷贝resolv.conf, hosts

         [root@TestAgent009 ~]# cp /etc/resolv.conf   /etc/dnsmasq.resolv.conf

         [root@TestAgent009 ~]# cp /etc/hosts   /etc/dnsmasq.hosts

  • 重启dnsmasq服务

          [root@TestAgent009 ~]# /etc/init.d/dnsmasq restart

  • 测试

          第一次:

          [root@TestAgent009 ~]# dig www.sina.com.cn

         ;; Query time: 30 msec
         ;; SERVER: 127.0.0.1#53(127.0.0.1)
         ;; WHEN: Thu May 19 20:12:31 2011
         ;; MSG SIZE  rcvd: 244

 

         再来一次:

         ;; Query time: 0 msec
         ;; SERVER: 127.0.0.1#53(127.0.0.1)
         ;; WHEN: Thu May 19 20:13:32 2011
         ;; MSG SIZE  rcvd: 130

         搞定收工

0 0