之前是用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 |
注意安装的时候,一定要选manual,不然之后的配置就没有用,我一开始就弄错的,选的是resolvconf
当然弄错也没关系,可以到/etc/default/pdnsd 中改过来
2./etc/pdnsd中的配置改成如下
03 |
cache_dir="/var/cache/pdnsd"; |
05 |
server_ip = eth0; // Use eth0 here if you want to allow other |
06 |
// machines on your network to query pdnsd. |
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). |
15 |
// Don't enable if you don't recurse yourself, can lead to problems |
16 |
// delegation_only="com","net"; |
像 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