使用djbdns创建DNS缓存
构建本地DNS缓存将加快您的互联网连接,因为假设DNS缓存从父DNS获取信息,因此“转换作业”(将域名转换为IP地址)的时间将变得可忽略。
FreeBSD已经在每个版本中发布绑定,但我更喜欢使用djbdns。
使用端口在FreeBSD中构建本地DNS缓存的简单方法:
1.安装djbdns端口
su-2.05b# whereis djbdns
djbdns: /usr/ports/dns/djbdns
su-2.05b# cd /usr/ports/dns/djbdns && make install clean
只需按OK,安装过程即可开始。
2.配置
# pw groupadd nofiles -g 800
# pw useradd dnslog -g nofiles -u 810 -d /nonexistent -s /sbin/nologin
# pw useradd dnscache -g nofiles -u 811 -d /nonexistent -s /sbin/nologin
这些命令将添加组nofile
,用户dnslog
和dnscache
。
# dnscache-conf dnscache dnslog /etc/dnscache 127.0.0.1
# ln -s /etc/dnscache /var/service
# echo ‘nameserver 127.0.0.1? >/etc/resolv.conf
这些命令将使IP地址127.0.0.1
成为该计算机的DNS缓存“唯一”。
为了能够在我们的网络中使用DNS缓存,我们需要发出更多的命令:
# dnscache-conf dnscache dnslog /etc/dnscache 192.168.1.1
# touch /etc/dnscache/root/ip/192.168.1
# ln -s /etc/dnscache /var/service
现在,每个客户端都可以添加192.168.1.1
作为有效的DNS解析器:
要使用“daemontools”权限,我们需要在rc.conf中
添加此条目:
svscan_enable=”YES”
第一次,我们需要手动启动它:
su-2.05b# /usr/local/etc/rc.d/svscan.sh start
检查运行服务:
su-2.05b# ps -ax | grep dns
338 ?? I 0:00.03 supervise dnscache
90515 ?? S 0:03.51 /usr/local/bin/dnscache
检查dnscache“真的有效”:
su-2.05b# tail -f /etc/dnscache/log/main/current
示例输出:
su-2.05b# tail -f /etc/dnscache/log/main/current
@4000000046375a22168f3ee4 cached 1 i.gtld-servers.net.
@4000000046375a22168fcf6c cached 1 j.gtld-servers.net.
@4000000046375a2216905ff4 cached 1 k.gtld-servers.net.
@4000000046375a221690ec94 cached 1 l.gtld-servers.net.
@4000000046375a2216917d1c cached 1 m.gtld-servers.net.
@4000000046375a22169209bc cached 1 a.gtld-servers.net.
@4000000046375a221692c154 cached 1 b.gtld-servers.net.
@4000000046375a22169351dc cached 1 c.gtld-servers.net.
@4000000046375a221693de7c cached 1 d.gtld-servers.net.
@4000000046375a2216945794 tx 0 255 mx44.alanistz.com. com. c005061e c0304f1e c036701e c023331e c037531e c02a5d1e c01a5c1e c0210e1e c029a21e c00c5e1e c02bac1e c01f501e c034b21e
@4000000046375a222673d964 rr cc4a7021 86400 1 mx74mi.clarmu.info. d035034a
@4000000046375a2226787514 rr cc4a7021 86400 1 mx144pb.clarmu.info. 42212090
@4000000046375a222678889c rr cc4a7021 86400 1 mx174hi.clarmu.info. 42f890ae
@4000000046375a222678983c rr cc4a7021 86400 1 mx187tr.clarmu.info. 416f11bb
@4000000046375a222678abc4 rr cc4a7021 86400 1 mx204pa.clarmu.info. 42217dcc
@4000000046375a222678bb64 rr cc4a7021 86400 ns clarmu.info. mx74mi.clarmu.info.
@4000000046375a222678ceec rr cc4a7021 86400 ns clarmu.info. mx204pa.clarmu.info.
@4000000046375a222678de8c rr cc4a7021 86400 ns clarmu.info. mx187tr.clarmu.info.
@4000000046375a222679059c rr cc4a7021 86400 ns clarmu.info. mx174hi.clarmu.info.
@4000000046375a222679153c rr cc4a7021 86400 ns clarmu.info. mx144pb.clarmu.info.
@4000000046375a22267924dc stats 379 144625 13 0
@4000000046375a2226793864 cached 1 mx74mi.clarmu.info.
@4000000046375a2226794804 cached 1 mx204pa.clarmu.info.
@4000000046375a22267957a4 cached 1 mx187tr.clarmu.info.
@4000000046375a2226796744 cached 1 mx174hi.clarmu.info
恭喜,您的DNS缓存正常运行。