示意图:
一、父域(gjp.com)的配置Red Hat Enterprise Linux 5.4
1.安装DNS
[root@gjp99 ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@gjp99 ~]# cd /mnt/cdrom/Server
[root@gjp99 Server]# ll bind*
-r--r--r-- 64 root root 1001253 Jul 31 2009 bind-9.3.6-4.P1.el5.i386.rpm
-r--r--r-- 64 root root 44959 Jul 31 2009 bind-chroot-9.3.6-4.P1.el5.i386.rpm
-r--r--r-- 73 root root 2900989 Jul 31 2009 bind-devel-9.3.6-4.P1.el5.i386.rpm
-r--r--r-- 73 root root 450930 Jul 31 2009 bind-libbind-devel-9.3.6-4.P1.el5.i386.rpm
-r--r--r-- 76 root root 877241 Jul 31 2009 bind-libs-9.3.6-4.P1.el5.i386.rpm
-r--r--r-- 64 root root 233804 Jul 31 2009 bind-sdb-9.3.6-4.P1.el5.i386.rpm
-r--r--r-- 64 root root 173772 Jul 31 2009 bind-utils-9.3.6-4.P1.el5.i386.rpm
[root@gjp99 Server]# rpm -ivh bind-9.3.6-4.P1.el5.i386.rpm
warning: bind-9.3.6-4.P1.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:bind ########################################### [100%]
[root@gjp99 Server]# rpm -ivh bind-chroot-9.3.6-4.P1.el5.i386.rpm
warning: bind-chroot-9.3.6-4.P1.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:bind-chroot ########################################### [100%]
[root@gjp99 Server]# rpm -ivh caching-nameserver-9.3.6-4.P1.el5.i386.rpm
warning: caching-nameserver-9.3.6-4.P1.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:caching-nameserver ########################################### [100%]
[root@gjp99 Server]# rpm -qip bind-9.3.6-4.P1.el5.i386.rpm
[root@gjp99 Server]# rpm -ql bind* //查看安装的文件路径
/etc/dbus-1/system.d/named.conf
/etc/logrotate.d/named
/etc/named.conf
/etc/rc.d/init.d/named
/etc/rndc.conf
/etc/rndc.key
2.DNS基本配置:
[root@gjp99 Server]# cd /var/named/chroot/
[root@gjp99 chroot]# ls
dev etc var
[root@gjp99 chroot]# cd etc
[root@gjp99 etc]# ll
total 16
-rw-r--r-- 1 root root 405 Aug 2 21:30 localtime
-rw-r----- 1 root named 1230 Jul 30 2009 named.caching-nameserver.conf
-rw-r----- 1 root named 955 Jul 30 2009 named.rfc1912.zones
-rw-r----- 1 root named 113 Aug 20 19:29 rndc.key
[root@gjp99 etc]# cp -p named.caching-nameserver.conf named.conf
不加-p的话 所属组为root,服务启动不了! //拷贝样例文件
[root@gjp99 etc]# ll
total 20
-rw-r--r-- 1 root root 405 Aug 2 21:30 localtime
-rw-r----- 1 root named 1230 Jul 30 2009 named.caching-nameserver.conf
-rw-r----- 1 root named 1230 Jul 30 2009 named.conf
-rw-r----- 1 root named 955 Jul 30 2009 named.rfc1912.zones
-rw-r----- 1 root named 113 Aug 20 19:29 rndc.key
[root@gjp99 etc]# vim named.conf
options {
listen-on port 53 { any; }; //监听端口
listen-on-v6 port 53 { ::1; };
directory "/var/named";检测的真实路径:/var/named/chroot/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";
allow-query { any; }; //允许查询
allow-query-cache { any; }; //允许查询缓存
};
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@gjp99 etc]# vim named.rfc1912.zones
增加以下信息:
zone "gjp.com" IN {
type master;
file "gjp.com.zone"; //要生成该文件
allow-update { none; };
};
[root@gjp99 chroot]# cd var/named/ //注意准确路径
[root@gjp99 named]# ll
total 36
drwxrwx--- 2 named named 4096 Aug 26 2004 data
-rw-r----- 1 root named 198 Jul 30 2009 localdomain.zone
-rw-r----- 1 root named 195 Jul 30 2009 localhost.zone
-rw-r----- 1 root named 427 Jul 30 2009 named.broadcast
-rw-r----- 1 root named 1892 Jul 30 2009 named.ca
-rw-r----- 1 root named 424 Jul 30 2009 named.ip6.local
-rw-r----- 1 root named 426 Jul 30 2009 named.local
-rw-r----- 1 root named 427 Jul 30 2009 named.zero
drwxrwx--- 2 named named 4096 Jul 27 2004 slaves
[root@gjp99 named]# cp -p localhost.zone gjp.com.zone //-p可以换成-a
[root@gjp99 named]# ll
total 40
drwxrwx--- 2 named named 4096 Aug 26 2004 data
-rw-r----- 1 root named 195 Jul 30 2009 gjp.com.zone
-rw-r----- 1 root named 198 Jul 30 2009 localdomain.zone
-rw-r----- 1 root named 195 Jul 30 2009 localhost.zone
-rw-r----- 1 root named 427 Jul 30 2009 named.broadcast
-rw-r----- 1 root named 1892 Jul 30 2009 named.ca //根指示文件
-rw-r----- 1 root named 424 Jul 30 2009 named.ip6.local
-rw-r----- 1 root named 426 Jul 30 2009 named.local
-rw-r----- 1 root named 427 Jul 30 2009 named.zero
drwxrwx--- 2 named named 4096 Jul 27 2004 slaves
[root@gjp99 named]#vim gjp.com.zone
[root@gjp99 named]# named-checkzone gjp.com gjp.com.zone
zone gjp.com/IN: loaded serial 42 OK
[root@gjp99 named]# named-checkconf /var/named/chroot/etc/named.conf
[root@gjp99 named]# service named start
Starting named: [ OK ]
[root@gjp99 ~]# tail -f /var/log/messages //监控日志情况
用实机测试(hostonly 与 vmware1 连接)
[root@gjp99 named]# vim /etc/resolv.conf //编辑过之后,在linux下才能使用nslookup
[root@gjp99 named]
# rndc reload //无需重启服务,只改变更新的!
server reload successful
[root@gjp99 named]# nslookup www.gjp.com
Server: 192.168.2.100
Address: 192.168.2.100#53
Name: www.gjp.com
Address: 192.168.2.100
二、配置子域bj.gjp.com
[root@gjp99 etc]# pwd
/var/named/chroot/etc
[root@gjp99 etc]# vim named.rfc1912.zones
增加以下信息:
zone "bj.gjp.com" IN {
type master;
file "bj.gjp.com.zone";
allow-update { none; };
};
[root@gjp99 ~]# cd /var/named/chroot/var/named
[root@gjp99 named]# cp -p gjp.com.zone bj.gjp.com.zone
[root@gjp99 named]# ll
total 44
-rw-r----- 1 root named 274 Aug 20 20:11 bj.gjp.com.zone
drwxrwx--- 2 named named 4096 Aug 20 20:23 data
-rw-r----- 1 root named 274 Aug 20 20:11 gjp.com.zone
-rw-r----- 1 root named 198 Jul 30 2009 localdomain.zone
-rw-r----- 1 root named 195 Jul 30 2009 localhost.zone
-rw-r----- 1 root named 427 Jul 30 2009 named.broadcast
-rw-r----- 1 root named 1892 Jul 30 2009 named.ca
-rw-r----- 1 root named 424 Jul 30 2009 named.ip6.local
-rw-r----- 1 root named 426 Jul 30 2009 named.local
-rw-r----- 1 root named 427 Jul 30 2009 named.zero
drwxrwx--- 2 named named 4096 Jul 27 2004 slaves
[root@gjp99 named]# vim bj.gjp.com.zone
[root@gjp99 etc]# rndc reload
server reload successful
[root@gjp99 etc]# nslookup www.bj.gjp.com
Server: 192.168.2.100
Address: 192.168.2.100#53
Name: www.bj.gjp.com
Address: 192.168.3.100
Windows下
三、委派子域 sh.gjp.com
[root@gjp99 named]# vim gjp.com.zone
[root@gjp99 named]# rndc reload
server reload successful
四、将被委派的主机配置: Red Hat Enterprise Linux 5.3
主机IP
Ping 父域所在的主机IP
安装 过程与父域主机相同
[root@www etc]# cp -p named.caching-nameserver.conf named.conf
[root@www etc]# pwd
/var/named/chroot/etc
[root@www etc]# cat 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";
allow-query { any; };
};
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@www etc]# vim named.rfc1912.zones
增加以下记录:
26 zone "sh.gjp.com" IN {
27 type master;
28 file "sh.gjp.com.zone";
29 allow-update { none; };
30 };
产生 sh.gjp.com.zone 文件
[root@www named]# pwd
/var/named/chroot/var/named
[root@www named]# cp -p localdomain.zone sh.gjp.com.zone
[root@www named]#vim sh.gjp.com.zone
[root@www named]# service named start
启动 named: [确定]
[root@www named]# vim /etc/resolv.conf
[root@www named]# rndc reload
server reload successful
[root@www named]# nslookup www.sh.gjp.com
Server: 192.168.2.12
Address: 192.168.2.12#53
Name: www.sh.gjp.com
Address: 192.168.4.100
在父域主机上测试:
[root@gjp99 named]# rndc flush //清缓存!
[root@gjp99 named]# nslookup www.sh.gjp.com
Server: 192.168.2.100
Address: 192.168.2.100#53
Non-authoritative answer:
Name: www.sh.gjp.com
Address: 192.168.4.100
RHEL 5.3被委派端:
无条件转发:
[root@www ~]# cd /var/named/chroot/etc
[root@www etc]# vim named.conf
无条件转发:forwarders {空格ip ; 空格};
[root@www etc]# nslookup www.gjp.com
Server: 192.168.2.12
Address: 192.168.2.12#53
Non-authoritative answer:
Name: www.gjp.com
Address: 192.168.2.100
[root@www etc]# nslookup www.bj.gjp.com
Server: 192.168.2.12
Address: 192.168.2.12#53
Non-authoritative answer:
Name: www.bj.gjp.com
Address: 192.168.3.100
有条件转发:
[root@www etc]# pwd
/var/named/chroot/etc
先删除上面的无条件转发:forwarders{ }
[root@www etc]# vim named.rfc1912.zones
增加如下信息:
26 zone "gjp.com" IN {
27 type forward;
28 forwarders { 192.168.2.100; };
29 };
[root@www etc]# rndc reload
server reload successful
[root@www etc]# rndc flush
[root@www etc]# nslookup www.gjp.com
Server: 192.168.2.12
Address: 192.168.2.12#53
Non-authoritative answer:
Name: www.gjp.com
Address: 192.168.2.100
[root@www etc]# nslookup www.bj.gjp.com
Server: 192.168.2.12
Address: 192.168.2.12#53
Non-authoritative answer:
Name: www.bj.gjp.com
Address: 192.168.3.100
四、用一台XP系统测试:
1.把DNS指向被委派的主机:(RHEL 5.3)
2.把DNS指向父域所在的dns服务器IP
本文转自 gjp0731 51CTO博客,原文链接:http://blog.51cto.com/guojiping/969738