需要安装的包:

 yum -y install bind bind-chroot caching-nameserver

安装bind-chroot后配置文件在/var/named/chroot/

安装caching-nameserver是为了在配置named.conf的时候有配置模版

 

 

DNS分享解析:

作用使不同的客户端解析相同的域名得到不同的IP地址

 

使用场景:

1、公司内外网都需要访问公司的域名(网站服务器放在内网),在公网地址有限的情况下,就不必花精力

moneyNAT回流了

2、网站提供外网访问的时候,电信的客户端访问的时候把域名解析成电信的服务器公网地址,网通的客户

端访问的时候解析成网通的服务器公网地址,解决跨运营商访问速度慢的问题,而且这样还可以视作已经做

了两条服务外网线路的负载均衡

 

实验效果:

192.168.10.20解析www.tarena.com 结果192.168.10.100

192.168.10.21解析www.tarena.com 结果192.168.10.101

其他主机解析www.tarena.com结果192.168.10.102

 

步骤:

一、修改配置文件named.conf

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

[root@ser1 etc]# cp -p named.caching-nameserver.conf named.conf

[root@ser1 etc]# vim named.conf

...

 14 acl lt { 192.168.10.20; };

 15 acl yd { 192.168.10.21; };

...

 17         listen-on port 53 { 192.168.10.10; };

...

 29         allow-query     { any; };

 30         allow-query-cache { any; };

...

 38 view lt_resolver {

 39         match-clients      { lt; };

 40         match-destinations { any; };

 41         recursion yes;

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

 43 };

 44 view yd_resolver {

 45         match-clients      { yd; };

 46         match-destinations { any; };

 47         recursion yes;

 48         include "/etc/named.yd.zones";

 49 };

 50 view other_resolver {

 51         match-clients      { any; };

 52         match-destinations { any; };

 53         recursion yes;

 54         include "/etc/named.other.zones";

 55 };

 

二、配置named.conf中指定的三个区域文件

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

...

  51 zone "tarena.com" IN {

 52         type master;

 53         file "lt.zone";

 54 };

[root@ser1 etc]# vim named.yd.zones

...

 51 zone "tarena.com" IN {

 52         type master;

 53         file "yd.zone";

 54 };

[root@ser1 etc]# vim named.other.zones

...

 51 zone "tarena.com" IN {

 52         type master;

 53         file "other.zone";

 54 };

检查语法是否正确

[root@ser1 etc]# named-checkconf named.conf

 

三、修改刚才区域文件中指定的三个数据库文件

[root@ser1 etc]# cd /var/named/chroot/var/named/

[root@ser1 named]# cp -p named.local lt.zone

[root@ser1 named]# cat lt.zone

$TTL    86400

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

                                      2013112101 ; Serial

                                      28800      ; Refresh

                                      14400      ; Retry

                                      3600000    ; Expire

                                      86400 )    ; Minimum

            IN      NS    dns1.tarena.com.

dns1   IN      A       192.168.10.10

www    IN      A       192.168.10.100

[root@ser1 named]# cp -p lt.zone yd.zone

[root@ser1 named]# cat yd.zone

$TTL    86400

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

                                      2013122101      ; serial

                                      3H              ; refresh

                                      15M             ; retry

                                      1W              ; expiry

                                      1D )            ; minimum

        IN      NS      dns1.tarena.com.

dns1    IN      A       192.168.10.10

www     IN      A       192.168.10.101

[root@ser1 named]# cp -p lt.zone other.zone

[root@ser1 named]# cat other.zone

$TTL    86400

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

                                     2013122101      ; serial                                           3H              ; refresh

                                     15M             ; retry

                                     1W              ; expiry

                                     1D )            ; minimum

        IN      NS      dns1.tarena.com.

dns1    IN      A       192.168.10.10

www     IN      A       192.168.10.102

 

四、启动服务并设置开机启动

[root@ser1 named]# service named restart

[root@ser1 named]# chkconfig named on

 

五、测试配置是否正确

用一台客户机分别配置成192.168.10.21192.168.10.20、和本地址段的其他IP地址

nslookup www.tarena.com 是否得到了想要的结果