bind配置dns服务的master与slave

发布时间:2020-12-15编辑:脚本学堂
bind配置dns服务的master与slave,供大家学习参考。

bind配置dns服务的master与slave,供大家学习参考。

需求:
解析域名
www.jbxue.org
www.jbxue.net
www.jb200.com

mail.jbxue.org
mail.jbxue.net
mail.jb200.com

mail服务器IP地址:
10.32.228.36
web服务器的IP地址:
10.32.228.12

首先,选用两台DNS服务器,master 为 10.232.23.35,slave 为 10.232.23.35
都是rhel5u4 bit64的机器。
在master 和 slave 机器上面分别执行
yum install bind caching-nameserver -y
然后能看到两个软件的版本是:
bind-9.3.6-20.P1.el5
caching-nameserver-9.3.6-20.P1.el5

安装成功后分别操作 master 和 slave 机器。

master 配置

cd /var/named/chroot/etc/
vim jbxue.zones
在其中添加jbxue的zone文件,内容如下:
 

复制代码 代码如下:

zone "jbxue.net" IN {
    type master;
    file "/var/named/chroot/var/named/cme/jbxue.net.zone";
    allow-update { none; };
};

zone "jb200.com" IN {
    type master;
    file "/var/named/chroot/var/named/cme/jb200.com.zone";
    allow-update { none; };
};

zone "jbxue.org" IN {
    type master;
    file "/var/named/chroot/var/named/cme/jbxue.org.zone";
    allow-update { none; };
};

zone "228.32.10-in-addr.arpa" IN {
    type master;
    file "/var/named/chroot/var/named/cme/228.32.10-in-addr.local";
    allow-update { none; };
};
 

保存,chown -R root:named jbxue.zones
然后,你懂得,添加zone文件。
分别创建文件
 

复制代码 代码如下:
/var/named/chroot/var/named/cme/jbxue.org.zone
/var/named/chroot/var/named/cme/jb200.com.zone
/var/named/chroot/var/named/cme/jbxue.net.zone
/var/named/chroot/var/named/cme/228.32.10-in-addr.local


内容相似:
比如 jbxue.org.zone内容为:
 

复制代码 代码如下:

$TTL    86400
@        IN SOA    localhost root (
                    43        ; serial (d. adams)
                    3H        ; refresh
                    15M        ; retry
                    1W        ; expiry
                    1D )        ; minimum
            IN NS        jbxue.org.
        IN MX 10    mail.jbxue.org.
;localhost    IN A        127.0.0.1

www     IN A            228.32.10.12
mail    IN A            228.32.10.36
 

如法泡制添加 com 和 net 的zone文件,注意要修改的NS记录值(com or net)。
.local文件内容为:
 

复制代码 代码如下:
$TTL    86400
@       IN      SOA     localhost. root.localhost.  (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
        IN      NS      jbxue.net.
        IN      NS      jb200.com.
        IN      NS      jbxue.org.
;1       IN      PTR     localhost.
12       IN      PTR     www.jbxue.net.
12       IN      PTR     www.jb200.com.
12       IN      PTR     www.jbxue.org.
36       IN      PTR     mail.jbxue.net.
36       IN      PTR     mail.jb200.com.
36       IN      PTR     mail.jbxue.org.
 

同样,修改这4个文件的owern为 root:named
然后,修改named.conf文件
ln -sf /etc/named.caching-nameserver.conf /var/named/chroot/etc/named.conf
然后修改 /var/named/chroot/etc/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";

    // Those options should be used carefully because they disable port
    // randomization
    // query-source    port 53;  
    // query-source-v6 port 53;

    allow-query     { any; };
    //allow-query-cache { localhost; };
    notify yes;
    allow-transfer  {any;};
    //transfer-source 10.32.228.36;
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
view localhost_resolver {
    match-clients        { any; };
    match-destinations { any; };
    //transfer-source 10.32.228.36;
    recursion yes;
    include "/etc/named.rfc1912.zones";
    include "/var/named/chroot/etc/jbxue.zones";
};
 

这样master 就OK了,可以测试下。
service named start
然后
dig @10.232.23.35 www.jbxue.org
dig @10.232.23.35 www.jbxue.net
dig @10.232.23.35 www.jb200.com
dig @10.232.23.35 mail.jbxue.org
dig @10.232.23.35 mail.jb200.com
dig @10.232.23.35 mail.jbxue.net

SLAVE端配置
首先,同样把 /etc/named.caching-nameserver.conf 连接成/var/named/chroot/etc/named.conf
然后修改/var/named/chroot/etc/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";

    // Those options should be used carefully because they disable port
    // randomization
    // query-source    port 53;  
    // query-source-v6 port 53;

    allow-query     { any; };
    //allow-query-cache { localhost; };
};
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";
    include "/var/named/chroot/etc/jbxue.zones";
};
能够看到我们添加的zone文件
include "/var/named/chroot/etc/jbxue.zones";
创建该文件:
vim /var/named/chroot/etc/jbxue.zones
内容为:
zone "jbxue.net" { type slave; file "slaves/jbxue.net";masters { 10.232.23.35; };};
zone "jbxue.org" { type slave; file "slaves/jbxue.org";masters { 10.232.23.35; };};
zone "jb200.com" { type slave; file "slaves/jb200.com";masters { 10.232.23.35; };};
保存,修改ower 为 root:named

清空slaves 目录
rm -fr /var/named/slaves/*
然后
在server 端查看日志:
tail -f /var/log/messages | grep named

在slave 端:
然后重新启动服务:
service named restart
ls /var/named/slaves/
jb200.com  jbxue.net  jbxue.org
就看到同步下来的zone文件了

server 端也能看到日志:
Aug 20 21:06:53 test023035.sqa.cm4 named[26858]: client 10.232.23.36#28603: view localhost_resolver: transfer of 'jbxue.org/IN': AXFR started
Aug 20 21:06:53 test023035.sqa.cm4 named[26858]: client 10.232.23.36#28603: view localhost_resolver: transfer of 'jbxue.org/IN': AXFR ended
Aug 20 21:06:53 test023035.sqa.cm4 named[26858]: client 10.232.23.36#30342: view localhost_resolver: transfer of 'jbxue.net/IN': AXFR started
Aug 20 21:06:53 test023035.sqa.cm4 named[26858]: client 10.232.23.36#10029: view localhost_resolver: transfer of 'jb200.com/IN': AXFR started
Aug 20 21:06:53 test023035.sqa.cm4 named[26858]: client 10.232.23.36#30342: view localhost_resolver: transfer of 'jbxue.net/IN': AXFR ended
Aug 20 21:06:53 test023035.sqa.cm4 named[26858]: client 10.232.23.36#10029: view localhost_resolver: transfer of 'jb200.com/IN': AXFR ended

然后我们在slave 端进行同样测试,选取slave 的IP为DNS服务器。
 

复制代码 代码如下:
dig @10.232.23.36 www.jbxue.org
dig @10.232.23.36 www.jbxue.net
dig @10.232.23.36 www.jb200.com
dig @10.232.23.36 mail.jbxue.org
dig @10.232.23.36 mail.jb200.com
dig @10.232.23.36 mail.jbxue.net
 

验证结果是否与master 一致。
至此,简单的master  -> slave 就搭建完成了。
你可以进行master端的更新进行进一步测试。