本文为大家介绍如何在centos5.4中配置缓存式dns服务,有需要的朋友可以参考下。
一.bind安装
bind相关的rpm包:
bind-sdb-9.3.6-4.P1.el5_4.2
ypbind-1.19-12.el5
bind-libbind-devel-9.3.6-4.P1.el5_4.2
bind-utils-9.3.6-4.P1.el5_4.2
bind-libs-9.3.6-4.P1.el5_4.2
bind-devel-9.3.6-4.P1.el5_4.2
bind-9.3.6-4.P1.el5_4.2
bind-chroot-9.3.6-4.P1.el5_4.2
另外还需要:
caching-nameserver-9.3.6-4.P1.el5_4.2
可以通过rpm -qa |grep bind
rpm -qa |grep caching-nameserver 来查找系统中这些包是否存在
通过rpm -rvh 将缺失的包安装到系统中
或者通过yum install bind*来升级和安装(如果网络配置好了就用这种办法)
二.BIND配置
由于chroot技术的使用,BIND配置文件named.conf在/var/named/chroot/etc/下,而区域配置文件在/var/named/chroot/var/named/下
另外其文件属性需要修改为root.named,否则会造成DNS解析错误。
chown root.named 文件名
如果是yum 安装的话不需要修改root named的文件所有者
配置域名:mail.sinoxxxxxx.com,机器IP:172.21.41.12
# cd /var/named/chroot/etc/
# ls -al
total 24
-rw-r--r-- 1 root root 405 Feb 7 19:36 localtime
-rw-r----- 1 root named 1230 Jan 21 00:33 named.caching-nameserver.conf
-rw-r----- 1 root named 955 Jan 21 00:33 named.rfc1912.zones
-rw-r----- 1 root named 113 Mar 18 16:33 rndc.key
以上是/var/named/chroot/etc/下的主要配置文件,不要去改动,
进行复制的时候要加上参数-P,这样文件的属性不会改变。
# cp -p named.caching-nameserver.conf named.conf
这样我们就可以用vi打开named.conf进行修改了
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
query-source port 53;
query-source-v6 port 53;
allow-query { any; };
allow-query-cache { any; };
forwarders {218.2.135.1;221.228.255.1;202.102.3.144;};
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
view localhost_resolver {
match-clients { any; };
match-destinations { any; };
recursion yes;
include "/etc/named.rfc1912.zones";
};
[root@localhost etc]# cp named.rfc1912.zones -p named.rfc1912.zones.bak
[root@localhost etc]# vi named.rfc1912.zones
// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone "." IN {
type hint;
file "named.ca";
};
zone "localdomain" IN {
type master;
file "localdomain.zone";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { none; };
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN
{
type master;
file "named.ip6.local";
allow-update { none; };
};
zone "255.in-addr.arpa" IN {
type master;
file "named.broadcast";
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.zero";
allow-update { none; };
};
zone "sinoxxxxxx.com" IN {
type master;
file "sinoxxxxxx.com.zone";
allow-update { none; };
};
zone "41.21.172.in-addr.arpa" IN {
type master;
file "172.21.41.zone";
allow-update { none; };
};
# cd /var/named/chroot/var/named/
# ls -al
drwxrwx--- 2 named named 4096 Aug 26 2004 data
-rw-r----- 1 root named 198 Dec 14 02:10 localdomain.zone
-rw-r----- 1 root named 195 Dec 14 02:10 localhost.zone
-rw-r----- 1 root named 427 Dec 14 02:10 named.broadcast
-rw-r----- 1 root named 1892 Dec 14 02:10 named.ca
-rw-r----- 1 root named 424 Dec 14 02:10 named.ip6.local
-rw-r----- 1 root named 426 Dec 14 02:10 named.local
-rw-r----- 1 root named 427 Dec 14 02:10 named.zero
drwxrwx--- 2 named named 4096 Jul 27 2004 slaves
# cp -p localdomain.zone sinoxxxxxx.com.zone
# cp -p named.local 172.21.41.zone
# vi 172.21.41.zone
这里的数字12是服务器地址的最后一位
# vi sinoxxxxxx.com.zone
vi /etc/resolv.conf
# /etc/init.d/named restart
Stopping named: [ OK ]
Starting named: [ OK ]
# chkconfig --level 345 named on
# nslookup
mail. sinoxxxxxx.com
Server: 172.21.41.12
Address: 172.21.41.12#53
Name: mail.sinoxxxxxx.com
Address: 172.21.41.12