实验拓扑:

         DNS Slave

-----DNS Master(vmnet1)----------(vmnet1)

         Win7 Client

实验一:搭建主DNS服务器

   tarena.com

   www.tarena.com  192.168.10.253

   bbs.tarena.com  192.168.10.100

   blog是bbs别名 

1、安装软件包

[root@localhost ~]# rpm -q bind bind-chrootcaching-nameserver

package bind is not installed

package bind-chroot is not installed

package caching-nameserver is not installed

[root@localhost ~]# yum -y install bind bind-chrootcaching- nameserver

2、修改主配置文件

[root@localhost ~]# cd /var/named/chroot/etc/

[root@localhostetc]# cp -pnamed.caching-nameserver.confnamed.conf

[root@localhostetc]# vimnamed.conf

15        listen-on port 53 { 192.168.10.253; };

16 //     listen-on-v6 port 53 { ::1; };

27        allow-query     { any; };

28        allow-query-cache { any; };

37        match-clients      { any; };

38        match-destinations { any; };

[root@localhostetc]# vim named.rfc1912.zones

 51 zone"tarena.com" IN {

 52         type master;

 53         file "tarena.com.zone";

54 };

 56 zone"10.168.192.in-addr.arpa" IN {

 57         type master;

 58         file "192.168.10.arpa";

59 };

[root@localhostetc]# named-checkconfnamed.conf

3、修改数据库文件

[root@localhostetc]# cd /var/named/chroot/var/named/

[root@localhost named]# cp -pnamed.localtarena.com.zone

[root@DNS01 named]# vimtarena.com.zone

$TTL    86400

@      IN      SOA     localhost. root.localhost.  (

2014061701 ; Serial

                                     28800      ; Refresh

                                      14400      ; Retry

                                     3600000    ; Expire

86400 )    ;Minimum

IN     NS      DNS01.tarena.com.

DNS01      IN      A       192.168.10.253

www        IN      A       192.168.10.253

bbs        IN      A       192.168.10.100

blog       IN    CNAME     bbs

 

[root@localhost named]# cp -p named.local192.168.10.arpa

[root@localhost named]# cattarena.com.zone

$TTL    86400

@      IN      SOA     localhost. root.localhost.  (

注释:“@”定义的是域名,相当于tarena.com2014061701 ; Serial

28800      ;Refresh

 14400      ; Retry

3600000    ;Expire

86400 )    ;Minimum

IN     NS      DNS01.tarena.com.

253        IN      PTR     DNS01.tarena.com.

253        IN      PTR     www.tarena.com.

100         IN     PTR     bbs.tarena.com.

100        IN      PTR     blog.tarena.com

[root@localhost named]#named-checkzonetarena.com tarena.com.zone

zone tarena.com/IN: loaded serial 1997022700

OK

[root@localhost named]#named-checkzonetarena.com  tarena.com.arpa

zone tarena.com/IN: loaded serial 1997022700

OK

4、启动服务

[root@localhost named]# service named restart

[root@localhost named]# chkconfig named on

5、指定搜索地址

[root@DNS01 named]# cat /etc/resolv.conf

searchlocaldomain

nameserver 192.168.10.253

6、客户机测试(首先将/etc/hosts文件中注释掉)

[root@PXE-server ~]# cat /etc/resolv.conf

search tarena.com

nameserver 192.168.10.253

 

[root@PXE-server ~]# nslookup 192.168.10.100

Server:        192.168.10.253

Address:       192.168.10.253#53

 

100.10.168.192.in-addr.arpa     name = bbs.tarena.com.

100.10.168.192.in-addr.arpa     name =blog.tarena.com.10.168.192.in-addr.arpa.

 

[root@PXE-server ~]# nslookup www.tarena.com

Server:        192.168.10.253

Address:       192.168.10.253#53

 

Name:  www.tarena.com

Address: 192.168.10.253

 

[root@PXE-server ~]# nslookup bbs.tarena.com

Server:        192.168.10.253

Address:       192.168.10.253#53

 

Name:  bbs.tarena.com

Address: 192.168.10.100

 

[root@PXE-server ~]# nslookup blog.tarena.com

Server:        192.168.10.253

Address:       192.168.10.253#53

 

blog.tarena.com canonical name = bbs.tarena.com.

Name:  bbs.tarena.com

Address: 192.168.10.100

-------------------------------------------------------------------------------

实验二:DNS高级应用

   实现DNS负载均衡,当用户访问www.tarena.com的时候,2/3用 户访问10.253,1/3用户访问10.100

   确保用户访问tarena.com的时候仍然可以访问www.tarena.com 的网站 

   实现用户在访问的时候只要域名正确就可以访问www.tarena.com 的网站

1、修改配置文件

[root@DNS01 named]# vimtarena.com.zone

$TTL    86400

@      IN      SOA     localhost. root.localhost.  (

2014061701 ; Serial

                                      28800      ; Refresh

                                     14400      ; Retry

                                     3600000    ; Expire

86400 )    ;Minimum

IN     NS      DNS01.tarena.com.

DNS01      IN      A       192.168.10.253

www        IN      A       192.168.10.253

www        IN      A       192.168.10.253

www        IN      A       192.168.10.100

bbs        IN      A       192.168.10.100

blog       IN    CNAME     bbs

tarena.com. IN    A        192.168.10.253

*           IN    A        192.168.10.100

重启服务:!ser或者service  named restart

2、客户机验证:

[root@PXE-server ~]# nslookup www.tarena.com

Server:        192.168.10.253

Address:       192.168.10.253#53

 

Name:   www.tarena.com

Address: 192.168.10.253

Name:   www.tarena.com

Address: 192.168.10.100

 

[root@PXE-server ~]# nslookup www.tarena.com

Server:        192.168.10.253

Address:       192.168.10.253#53

 

Name:   www.tarena.com

Address: 192.168.10.100

Name:   www.tarena.com

Address: 192.168.10.253

 

[root@PXE-server ~]# host www.tarena.com

www.tarena.com has address 192.168.10.253

www.tarena.com has address 192.168.10.100

---------------------------------------------------------------------------------

实验三:搭建从DNS服务器

   给上面的主DNS搭建一个辅助DNS

1、安装软件包

[root@localhost ~]# rpm -q bind bind-chroot caching-nameserver

package bind is not installed

package bind-chroot is not installed

package caching-nameserver is not installed

[root@localhost ~]# yum -y install bind bind-chroot caching-nameserver

2、修改从DNS的主配置文件

方法一:

[root@localhost ~]# cd /var/named/chroot/etc/

[root@localhostetc]# cp -pnamed.caching-nameserver.confnamed.conf

[root@localhostetc]# vimnamed.conf

listen-on port 53 { 192.168.10.100; };

allow-query     { any; };

allow-query-cache { any; };

match-clients      { any;};

match-destinations { any; };

[root@ser2 etc]# vim named.rfc1912.zones

zone "tarena.com" IN {

type slave;

file "slaves/tarena.com.zone";

masters { 192.168.10.253; };

  };

zone "10.168.192.in-addr.arpa" IN {

type slave;

file "slaves/tarena.com.arpa";

masters { 192.168.10.253; };

 };

[root@ser2 etc]# named-checkconfnamed.conf

 

方法二、

[root@localhost ~]# cd /var/named/chroot/etc/

[root@localhostetc]# cp -pnamed.caching-nameserver.confnamed.conf

[root@localhostetc]# vimnamed.conf

listen-on port 53 { 192.168.10.100; };

allow-query     { any; };

allow-query-cache { any; };

match-clients      { any;};

match-destinations { any; }

可以把view命令包含的注释掉,将/etc/named.rfc1912.zones所需要配置的命令在此写完整。具体命令操作如下:

#view  localhost_resolver {

#       match-clients      { any; };

#       match-destinations{ any; };

#       recursion yes;

#       include"/etc/named.rfc1912.zones";

#};

 

zone "tarena.com" IN {

type slave;

file "slaves/tarena.com.zone";

masters  { 192.168.10.253;};

};

zone "10.168.192.in-addr.arpa" IN {

type slave;

file "slaves/192.168.10.arpa";

masters { 192.168.10.253; };

};

3、修改主DNS的主配置文件,添加授权信息

[root@localhost ~]# cd /var/named/chroot/etc/

[root@localhostetc]# vim named.conf    //添加21行内容

...

 21         allow-transfer { 192.168.10.100; };

...

[root@localhostetc]# cd /var/named/chroot/var/named/

[root@localhost named]# cattarena.com.zone

$TTL    86400

@       IN      SOA    tarena.com. root.tarena.com.  (

                                     2014041802 ; Serial   //序列号加1

                                     28800      ; Refresh

                                     14400      ; Retry

                                     3600000    ; Expire

86400 )    ; Minimum

IN      NS      dns01.tarena.com.

IN      NS      dns02.tarena.com.  //添加从DNS服务器

        IN      A      192.168.10.253

dns01    IN      A      192.168.10.253

dns02    IN      A      192.168.10.100   //为从DNS正向解析

www    IN      A      192.168.10.253

www    IN      A      192.168.10.253

www     IN      A      192.168.10.100

bbs     IN      A      192.168.10.100

blog    IN      CNAME  bbs

$GENERATE 20-50 station$ IN A  192.168.10.$

*       IN      A      192.168.10.101

[root@localhost named]# cattarena.com.arpa

$TTL    86400

@       IN      SOA    tarena.com. root.tarena.com.  (

                                     2014041802 ; Serial      //序列号加1

                                     28800      ; Refresh

                                     14400      ; Retry

                                      3600000    ; Expire

86400 )    ; Minimum

IN      NS      dns01.tarena.com.

IN      NS      dns02.tarena.com.           //添加从DNS服务器

253      IN      PTR    dns01.tarena.com.

100     IN      PTR    dns02.tarena.com.       //为从DNS反向解析

253      IN      PTR    www.tarena.com.

100      IN      PTR    bbs.tarena.com.

[root@localhostetc]# service named restart

4、启动从DNS服务器并验证

[root@localhostetc]# service named restart

[root@localhostetc]# chkconfig named on

[root@localhostetc]# ls /var/named/chroot/var/named/slaves/

tarena.com.zonetarena.com.arpa

[root@PXE-server slaves]# vimtarena.com.zone

$ORIGIN .

$TTL 86400      ; 1 day

tarena.com              INSOA  localhost. root.localhost. (

2014061702 ; serial

                               28800      ; refresh (8 hours)

                               14400      ; retry (4 hours)

                               3600000    ; expire (5 weeks 6days 16 hours)

                               86400      ; minimum (1 day)

                               )

NS      192.168.10.253.tarena.com.

NS      DNS01.tarena.com.

NS      DNS02.tarena.com.

                       A       192.168.10.253

$ORIGIN tarena.com.

*                      A       192.168.10.1

bbs                    A       192.168.10.101

blog                    CNAME  bbs

DNS01                  A       192.168.10.253

DNS02                  A       192.168.10.101

station20              A       192.168.10.20

station21              A       192.168.10.21