Linux下用pdnsd做dns缓存服务器

1
2
3
sudo pacman -S pdnsd
cd /etc
sudo cp pdnsd.conf.sample pdnsd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[admin@huangye etc]$ cat pdnsd.conf
global {
    perm_cache=1024;
    cache_dir="/var/cache/pdnsd";
#   pid_file = /var/run/pdnsd.pid;
    run_as="nobody";
    server_ip = eth0;  # Use eth0 here if you want to allow other
                # machines on your network to query pdnsd.
    status_ctl = on;
#   paranoid=on;       # This option reduces the chance of cache poisoning
                       # but may make pdnsd less efficient, unfortunately.
    query_method=udp_tcp;
    min_ttl=48h;       # Retain cached entries at least 15 minutes.
    max_ttl=1w;        # One week.
    timeout=10;        # Global timeout option (10 seconds).
    neg_domain_pol=on;
}

# The following section is most appropriate if you have a fixed connection to
# the Internet and an ISP which provides good DNS servers.
server {
    label= "myisp";
    ip = 你的ISP的DNS,8.8.8.8;  # Put your ISP's DNS-server address(es) here.
    timeout=4;         # Server timeout; this may be much shorter
               # that the global timeout option.
    uptest=if;         # Test if the network interface is active.
    interface=eth0;    # The name of the interface to check.
    interval=60m;      # Check every 60 minutes.
    purge_cache=off;   # Keep stale cache entries in case the ISP's
               # DNS servers go offline.
}

source {
    owner=localhost;
#   serve_aliases=on;
    file="/etc/hosts";
}

rr {
    name=localhost;
    reverse=on;
    a=127.0.0.1;
    owner=localhost;
    soa=localhost,root.localhost,42,86400,900,86400,86400;
}

min_ttl我调整为了48h ,最短要48个小时更新一次缓存。

interval=60m ,每60分钟检测一次。
注意,如果你想让同网段其它人也能查询的话,server_ip 的值设置为eth0 ,如果你只想自己使用的话,填写 127.0.0.1 即可。
然后,启动服务:

1
sudo /etc/rc.d/pdnsd start

然后,修改本机DNS配置:

1
sudo vim resolv.conf

把其它dns全部注释掉,
如果你server_ip 的值设置为eth0 的话,nameserver 后面要填写你本机当前的IP地址,经测试,填写127.0.0.1不能工作。否则,你可以添加下面这条:

1
nameserver 127.0.0.1

现在

1
dig ihacklog.com

第一次:
Query time: 353 msec

其后基本上是:
Query time: 17 msec

更多
5 Responses Post a comment
  1. vx13

    我想知道,对于正常人类,1ms 和 17ms 有“体感差异”吗? dnsmasq 的功能比较复杂,整合了基本的 dns 、 dhcp 、 tftp ,和 pdns 比起来,占用的资源恐怕是有差别的。

  2. Linux下用dnsmasq做dns cache server

    [...] @依云说这个速度快,我试了下,果然。 目前最新版是2.58 ,可去其FTP下载:http://www.thekelleys.org.uk/dnsmasq/ 12345678sudo pacman -S --needed dnsmasq cd /etc [admin@huangye etc]$ sudo cp -v dnsmasq.conf{,.orig} `dnsmasq.conf' -> `dnsmasq.conf.orig' [admin@huangye etc]$ sudo vim dnsmasq.conf [...]

  3. 荒野无灯

    @依云
    啊,我刚才安装这个试了下,稳定在 1 ms :twisted: !不错,去其FTP看了下,更新也比较快。

  4. 依云

    哈,我用的 dnsmasq,刚刚 dig 了下,才 3ms~

Leave a Reply

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS