原文的路径:http://zabc.blogbus.com/logs/62117854.html
RHEL5自带BIND9的安装配置
需要安装的包
system-config-bind-4.0.3-2.el5
bind-9.3.4-6.P1.el5
bind-libs-9.3.4-6.P1.el5
bind-utils-9.3.4-6.P1.el5
bind-chroot-9.3.4-6.P1.el5
caching-nameserver-9.3.4-6.P1.el5
[root@vmrhel5 etc]# more /etc/sysconfig/named
ROOTDIR=/var/named/chroot ##显示chroot目录是/var/named/chroot
chroot下原有文件为
[root@vmrhel5 etc]# cd /var/named/chroot/etc
[root@vmrhel5 etc]# pwd
/var/named/chroot/etc
[root@vmrhel5 etc]# ll
total 32
-rw-r--r-- 1 root root 405 Jan 18 2009 localtime
-rw-r----- 1 root named 1100 Feb 29 2008 named.caching-nameserver.conf
-rw-r----- 1 root named 955 Feb 29 2008 named.rfc1912.zones
-rw-r----- 1 root named 113 Apr 11 18:37 rndc.key
复制模板文件得到named.conf,文件属主为root.named
[root@vmrhel5 etc]# cp -a named.caching-nameserver.conf named.conf
[root@vmrhel5 etc]# ll
total 40
-rw-r--r-- 1 root root 405 Jan 18 2009 localtime
-rw-r----- 1 root named 1100 Feb 29 2008 named.caching-nameserver.conf
-rw-r----- 1 root named 1100 Feb 29 2008 named.conf
-rw-r----- 1 root named 955 Feb 29 2008 named.rfc1912.zones
-rw-r----- 1 root named 113 Apr 11 18:37 rndc.key
##cp -a
-a, --archive same as -dpR
-d same as --no-dereference --preserve=link
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: links, all
-R, -r, --recursive copy directories recursively
##
编辑named.conf文件
[root@vmrhel5 etc]# vi named.conf
options {
listen-on port 53 { 127.0.0.1;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;
forwarders { 192.168.1.1; };
allow-transfer { 192.168.1.2;192.168.1.11; };
allow-query { 192.168.0.0/24;192.168.1.0/24; };
};
include "/etc/rndc.key" ;
view "internal" {
match-clients { 192.168.1.0/24; };
match-destinations { any; };
recursion yes;
include "/etc/internal.zones";
include "/etc/intranet.zones";
};
//view "external" {
// match-clients { !192.168.1.0/24; };
// match-destinations { !localhost; };
// recursion no;
// include "/etc/external.zones";
//};
1:侦听本机所有IP的DNS请求,但只响应192.168.0.0/24及192.168.1.0/24二个网段的客户端。
2:当客户的IP属于192.168.1.0/24网段时,启用/etc/internal.zones这个主配置文件; 当客户的IP不属于192.168.1.0/24网段时,启用/etc/external.zones这个主配置文件
[root@vmrhel5 ~]# rndc-confgen -b 512 -k rndckey > /var/named/chroot/etc/rndc.conf
[root@vmrhel5 etc]# more rndc.conf
# Start of rndc.conf
key "rndckey" {
algorithm hmac-md5;
secret "2LCjhE/whqwgqI0OBYab40nS5rN3Tr5n8uRDNJgD+rDDutpnCd57NI8k9YcU+5NmGyS4spfNmVMHpeTTKbMBdA==";
};
options {
default-key "rndckey";
default-server 127.0.0.1;
default-port 953;
};
# End of rndc.conf
# Use with the following in named.conf, adjusting the allow list as needed:
# key "rndckey" {
# algorithm hmac-md5;
# secret "2LCjhE/whqwgqI0OBYab40nS5rN3Tr5n8uRDNJgD+rDDutpnCd57NI8k9YcU+5NmGyS4spfNmVMHpeTTKbMBdA==";
# };
#
# controls {
# inet 127.0.0.1 port 953
# allow { 127.0.0.1; } keys { "rndckey"; };
# };
# End of named.conf
[root@vmrhel5 etc]# head -n 5 rndc.conf|grep -v "# Start of rndc.conf" >rndc.key
[root@vmrhel5 etc]# vi rndc.key
key "rndckey" {
algorithm hmac-md5;
secret "2LCjhE/whqwgqI0OBYab40nS5rN3Tr5n8uRDNJgD+rDDutpnCd57NI8k9YcU+5NmGyS4spfNmVMHpeTTKbMBdA==";
};
创建主配置文件
在etc目录下有一个主配置的例子文件,将其复制一份改名为internal.zones。
如下图复制时一定要加-a,因为如果主配置文件的拥有组不是named时,BIND服务是无法运行的。
[root@vmrhel5 etc]# cp -a named.rfc1912.zones internal.zones
##internal.zones内容无需修改
[root@vmrhel5 etc]# more intranet.zones
zone "xyz.com" IN {
type master;
file "data/xyz.com.zone";
allow-update { none; };
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "data/192.168.1.zone";
allow-update { none; };
};
zone "abc.com" IN {
type slave;
masters { 192.168.1.11; };
file "slaves/abc.com.zone";
allow-update { none; };
};
[root@vmrhel5 etc]# chown root.named intranet.zones rndc.conf rndc.key
[root@vmrhel5 etc]# ll
total 64
-rw-r----- 1 root named 955 Feb 29 2008 internal.zones
-rw-r----- 1 root named 348 Apr 13 14:47 intranet.zones
-rw-r--r-- 1 root root 405 Jan 18 2009 localtime
-rw-r----- 1 root named 1100 Feb 29 2008 named.caching-nameserver.conf
-rw-r----- 1 root named 1631 Apr 13 16:04 named.conf
-rw-r----- 1 root named 955 Feb 29 2008 named.rfc1912.zones
-rw-r--r-- 1 root named 603 Apr 13 14:29 rndc.conf
-rw-r--r-- 1 root named 154 Apr 13 14:34 rndc.key
创建区域文件
[root@vmrhel5 named]# pwd
/var/named/chroot/var/named
[root@vmrhel5 named]# ll
total 72
drwxrwx--- 2 root named 4096 Apr 13 14:46 data
-rw-r----- 1 root named 198 Feb 29 2008 localdomain.zone
-rw-r----- 1 root named 195 Feb 29 2008 localhost.zone
-rw-r----- 1 root named 427 Feb 29 2008 named.broadcast
-rw-r----- 1 root named 1892 Feb 29 2008 named.ca
-rw-r----- 1 root named 424 Feb 29 2008 named.ip6.local
-rw-r----- 1 root named 426 Feb 29 2008 named.local
-rw-r----- 1 root named 427 Feb 29 2008 named.zero
drwxrwx--- 2 named named 4096 Apr 13 15:01 slaves
[root@vmrhel5 named]# cd data
[root@vmrhel5 data]# ls
192.168.1.zone named_mem_stats.txt named.run xyz.com.zone
[root@vmrhel5 data]# more xyz.com.zone
$TTL 86400
@ IN SOA xyz.com. root (
2010041200 ; Serial
1H ; Refresh
15M ; Retry
1W ; Expire
1D ) ; Minimum
IN NS @
IN A 192.168.1.4
IN MX 10 mail
www IN A 192.168.1.4
mail IN A 192.168.1.4
news IN CNAME www
[root@vmrhel5 data]# more 192.168.1.zone
$TTL 86400
@ IN SOA xyz.com. root.xyz.com. (
2010041200 ; Serial
1H ; Refresh
15M ; Retry
1W ; Expire
1D ) ; Minimum
IN NS xyz.com.
4 IN PTR www.xyz.com.
1:选项配置如下:
◆ listen-on port 53 { 127.0.0.1; };这个是DNS侦听本机的端口及IP。这里设置表示只侦听127.0.0.1这个地址。如不定义此选项表示侦听所有网络
◆ directory “/var/named”指主配置文件路径,这个路径也是相对路径,它的绝对路径/var/named/chroot/var/named
◆ query-source port 53;客户端在进行DNS查询时必须使用53做为源端口
◆ allow-query { localhost; };允许提交查询的客户端,如不定义此选项表示允许所有查询
◆ allow-recursion {192.168.0.0/24;192.168.0.1/24}:允许提交递归查询的客户端,如不定义此选项表示允许所有
◆ allow-transfer {192.168.0.254;}:允许区域传输的DNS服务器(辅助DNS),不写表示允许所有
◆ forwarders {192.168.0.9;}:转发器
◆ forward only|first:only表示如果在指定的转发器找不到,不会去向根查询,first表示快速转发(默认)
2:定义主配置文件,此部分可有多个,只要求localhost_resolver这个名字不重复
◆ match-clients { localhost; };客户端的源IP
◆ match-destinations { localhost; };解析出的目标IP
◆ recursion yes;如果客户端提交的FQDN本服务器没有,那么服务器会帮助客户端去查询
◆ include “/etc/named.rfc1912.zones”; 指定主配置文件
上面参数中所有指定地址范围(如:listen-on、match-clients等)时都可以多个写法如下:
◆ 单个IP:192.168.0.1;
◆ 网段:192.168.0.0/24;
◆ 指定多个IP:192.168.0.1;192.168.0.2;
◆ 网段:192.168.0.;
还可以使用!表示不包括
◆ none:不匹配所有
◆ any:匹配所有
◆ localhost:DNS主机
◆ localnet:与DNS主机同网段
zone:指定区域名称;type:指定类型
Master
主DNS服务器:拥有区域数据文件,并对此区域提供管理数据
Slave
辅助区域:拥有主DNS服务器区域数据文件的副本,辅助DNS服务器从主DNS服务器同步所有区域数据
Stub
stub区域和slave类似,但它只复制主DNS服务器上的NS记录,而不像辅助DNS服务器会复制所有区域数据
Forward
一个forward zone是每个域的配置转发的主要部分。一个zone语句中的type forward可以包括一个forward和或forwarders子句,它会在区域名称给定的域中查询。如果没有forwarders语句或forwarders是空表,那么这个域就不会转发,消除了options语句中有关转发的配置
Hint
根域名服务器的初始化组指定使用的线索区域hint zone,当服务器启动时,它使用根线索来查找根域名服务器,并找到最近的根域名服务器列表。如果没有指定class IN的线索区域,服务器使用编译时默认的根服务器线索。不是IN的类别没有内置的默认线索服务器
file:指定区域配置文件,该文件中将定义资源记录allow-update:指定动态更新类型,none表示不允许动态更新