ubuntu 上用pdnsd做dns缓存

之前是用dnsmasq做dns缓存的,但是dnsmasq不可以用tcp方式查询dns,也不能缓存足够大的dns信息,所以google了一下,发现了pdnsd

1.安装

1 <span style="font-family:arial,helvetica,sans-serif;"><span style="font-size:14px;">sudo apt-get install pdnsd
2 </span></span>

注意安装的时候,一定要选manual,不然之后的配置就没有用,我一开始就弄错的,选的是resolvconf

当然弄错也没关系,可以到/etc/default/pdnsd 中改过来

 

1 vi /etc/default/pdnsd
2 # do we start pdnsd ?
3 START_DAEMON=yes
4 # auto-mode, overrides /etc/pdsnd.conf if set [see /usr/share/pdnsd/]
5 AUTO_MODE=
6 # optional CLI options to pass to pdnsd(8)
7 START_OPTIONS=

2./etc/pdnsd中的配置改成如下

01 global{
02         perm_cache=2048;
03         cache_dir="/var/cache/pdnsd";
04         run_as="pdnsd";
05         server_ip = eth0;  // Use eth0 here if you want to allow other
06                                 // machines on your network to query pdnsd.
07         status_ctl = on;
08         paranoid=on;
09         query_method=tcp_only;  // pdnsd must be compiled with tcp
10                                 // query support for this to work.
11         min_ttl=24h;       // Retain cached entries at least 15 minutes.
12         max_ttl=1w;        // One week.
13         timeout=10;        // Global timeout option (10 seconds).
14         neg_domain_pol=on;
15         // Don't enable if you don't recurse yourself, can lead to problems
16         // delegation_only="com","net";
17 }
18 server {
19     label= "myisp";
20     ip = 8.8.8.8;  # Put your ISP's DNS-server address(es) here.
21     timeout=4;         # Server timeout; this may be much shorter
22                # that the global timeout option.
23     uptest=if;         # Test if the network interface is active.
24     interface=eth0;    # The name of the interface to check.
25     interval=60m;      # Check every 60 minutes.
26     purge_cache=off;   # Keep stale cache entries in case the ISP's
27                # DNS servers go offline.
28 }

像 global设置中我就把query_method 改成了tcp_only方式,还有udp_only|tcp_udp|udp_tcp ,并且讲min_ttl=96h;的值调大,这样就可以咯,缓存的dns记录最少会保留96个小时,最后pdnsd-ctl status 应该会出现Server 0    label: myisp 这里的label应该跟你设置的label一样,我之前由于选错配置是resolvconf 。

更 新:我在服务器上搭dns的目的就是为了给同学直接提供某些服务的免翻服务,所以/etc/hosts中本来就写有大量的hosts ,从google code 上的smarthost而来,所以对我来说dns最重要的就是dns的反欺骗,但是有些时候tcp包不能免费发出去(学校原因不解释),不得已把查询方式 改成tcp_udp 所以这里在global中又需要多设置一个tcp_qtimeout=1 ,必须设置,因为默认值30s,timeout值越低越好,同时又加了一条par_queries=2; 同时从两个服务器查询。

再更新:查看和清除cache的命令分别是pdnsd-ctl dump     pdnsd-ctl empty-cache

参考:官方wiki http://www.phys.uu.nl/~rombouts/pdnsd/doc.html

            arch       https://wiki.archlinux.org/index.php/Pdnsd

 

转自:http://lovejoy.my.phpcloud.com/ubuntu-pdnsd-tcp.html

posted @ 2012-12-16 19:27  Jog  阅读(2240)  评论(0)    收藏  举报