linux 主从DNS服务器配置

环境

主DNS:192.168.14.164
主DNS:192.168.14.165
系统版本:redhat 6.5

一、主DNS配置

1、主备安装dns服务yum install bind*

[root@jbdb1 mnt]# yum install bind*
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel                                                                                                                                         | 3.9 kB     00:00 ... 
Setting up Install Process
Package 32:bind-utils-9.8.2-0.17.rc1.el6_4.6.x86_64 already installed and latest version
Package 32:bind-libs-9.8.2-0.17.rc1.el6_4.6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be installed
---> Package bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be installed
---> Package bind-dyndb-ldap.x86_64 0:2.3-5.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================
 Package                                  Arch                            Version                                               Repository                     Size
====================================================================================================================================================================
Installing:
 bind                                     x86_64                          32:9.8.2-0.17.rc1.el6_4.6                             rhel                          4.0 M
 bind-chroot                              x86_64                          32:9.8.2-0.17.rc1.el6_4.6                             rhel                           71 k
 bind-dyndb-ldap                          x86_64                          2.3-5.el6                                             rhel                           69 k

Transaction Summary
====================================================================================================================================================================
Install       3 Package(s)

Total download size: 4.1 M
Installed size: 7.4 M
Is this ok [y/N]: y
Downloading Packages:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                57 MB/s | 4.1 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64                                                                                                            1/3 
  Installing : 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64                                                                                                     2/3 
  Installing : bind-dyndb-ldap-2.3-5.el6.x86_64                                                                                                                 3/3 
  Verifying  : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64                                                                                                            1/3 
  Verifying  : 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64                                                                                                     2/3 
  Verifying  : bind-dyndb-ldap-2.3-5.el6.x86_64                                                                                                                 3/3 

Installed:
  bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6                bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6                bind-dyndb-ldap.x86_64 0:2.3-5.el6               

Complete!
[root@jbdb1 mnt]# 
[root@jbdb1 mnt]# 

2、修改主配置文件

vim /etc/named.conf

[root@jbdb1 mnt]# more /etc/named.conf 
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
#全局配置参数
options {
        listen-on port 53 { 127.0.0.1; };   #监听地址端口
        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; };          #默认localhost,允许查询IP
        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
#配置正向解析
zone "." IN {
        type hint;
        file "named.ca";
};
zone "." IN {
        type hint;
        file "named.ca";
};
zone "zjzfgjj.org" IN {             #添加zym.com域
        type master;                #指定类型为主
        file "zjzfgjj.org.zone";    #指定区域数据库文件名
};
zone "zjzfgjj.gov.cn" IN {
        type master;
        file "zjzfgjj.gov.cn.zone";
};
#配置反向解析
zone "192.168.41.in-addr.arpa" IN {
        type master;
        file "192.168.41.in-addr.arpa";
};

zone "192.168.32.in-addr.arpa" IN {
        type master;
        file "192.168.32.in-addr.arpa";
};


include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

3、创建解析文件

[root@jbdb1 named]# cp -a named.localhost zjzfgjj.org.zone
[root@jbdb1 named]# cp -a named.localhost zjzfgjj.gov.cn.zone
[root@jbdb1 named]# cp -a named.loopback 192.168.41.in-addr.arpa
[root@jbdb1 named]# cp -a named.loopback 192.168.32.in-addr.arpa
[root@jbdb1 ~]#   more /var/named/zjzfgjj.gov.cn.zone 
$TTL 1D
@       IN SOA  master.zjzfgjj.org zjzfgjj.gov.cn. (
                                        2018121901      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN      NS      master
        IN      NS      slave
master  IN      A       192.168.14.164
slave   IN      A       192.168.14.165
un02    IN      A       192.168.32.15
un03    IN      A       192.168.14.124
[root@jbdb1 ~]# 
[root@jbdb1 ~]#   more /var/named/zjzfgjj.org.zone 
$TTL 1D
@       IN SOA  master.zjzfgjj.org zjzfgjj.org.(
                                        2018121901      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN      NS      master
        IN      NS      slave
master  IN      A       192.168.14.164
slave   IN      A       192.168.14.165
un01    IN      A       192.168.41.249
[root@jbdb1 ~]# 
[root@jbdb1 ~]#   more /var/named/192.168.32.in-addr.arpa 
$TTL 1D
@       IN SOA  master.zjzfgjj.org zjzfgjj.gov.cn. (
                                        2018013002      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN      NS      master.zjzfgjj.org.
15      IN      PTR     un02.zjzfgjj.gov.cn
[root@jbdb1 ~]# 
[root@jbdb1 ~]#   more /var/named/192.168.32.in-addr.arpa 
$TTL 1D
@       IN SOA  master.zjzfgjj.org zjzfgjj.gov.cn. (
                                        2018013002      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN      NS      master.zjzfgjj.org.
15      IN      PTR     un02.zjzfgjj.gov.cn
[root@jbdb1 ~]# 

4、检查语法

[root@centos7~ ]#named-checkconf  #检查配置文件中的语法/etc/named.conf /etc/named.rfc1912.zones
[root@centos7~ ]#named-checkzone zym.com /var/named/zym.com.zone #解析库文件语法检查
[root@centos7~ ]#rndc reload     #加载DNS配置文件  

5、启动服务测试

[root@jbdb1 ~]# service named start

1、配置主机dns

[root@jbdb2 ~]# more /etc/resolv.conf 
# Generated by NetworkManager


# No nameservers found; try putting DNS servers into your
# ifcfg files in /etc/sysconfig/network-scripts like so:
#
# DNS1=xxx.xxx.xxx.xxx
# DNS2=xxx.xxx.xxx.xxx
# DOMAIN=lab.foo.com bar.foo.com
dns1=192.168.14.164
dns2=192.168.14.165
[root@jbdb2 ~]# 

2、测试

[root@jbdb2 ~]# dig un01.zjzfgjj.org

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> un01.zjzfgjj.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15974
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2

;; QUESTION SECTION:
;un01.zjzfgjj.org.              IN      A

;; ANSWER SECTION:
un01.zjzfgjj.org.       86400   IN      A       192.168.41.249

;; AUTHORITY SECTION:
zjzfgjj.org.            86400   IN      NS      slave.zjzfgjj.org.
zjzfgjj.org.            86400   IN      NS      master.zjzfgjj.org.

;; ADDITIONAL SECTION:
master.zjzfgjj.org.     86400   IN      A       192.168.14.164
slave.zjzfgjj.org.      86400   IN      A       192.168.14.165

;; Query time: 1 msec
;; SERVER: ::1#53(::1)
;; WHEN: Wed Jan 12 03:23:12 2022
;; MSG SIZE  rcvd: 123

[root@jbdb2 ~]# 

二、备dns配置

1、备库修改主配置文件

[root@jbdb2 ~]# more /etc/named.conf 
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
        listen-on port 53 { 192.168.14.0/24; };
        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; };
        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "zjzfgjj.org" IN {
        type slave;
        file "slaves/zjzfgjj.org.zone";
        masters { 192.168.14.164; };
};
zone "zjzfgjj.gov.cn" IN {
        type slave;
        file "slaves/zjzfgjj.gov.cn.zone";
        masters { 192.168.14.164; };
};

zone "192.168.41.in-addr.arpa" IN {
        type slave;
        file "slaves/192.168.41.in-addr.arpa";
        masters {192.168.14.164;};
};

zone "192.168.32.in-addr.arpa" IN {
        type slave;
        file "slaves/192.168.32.in-addr.arpa";
        masters {192.168.14.164;};
};


include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

[root@jbdb2 ~]#   

备库只需要配置named.conf文件,其它文件会自动同步。

2、启动服务

[root@jbdb2 ~]#   service named start
[root@jbdb2 ~]# ls /var/named/slaves/
192.168.32.in-addr.arpa  192.168.41.in-addr.arpa  zjzfgjj.gov.cn.zone  zjzfgjj.org.zone
[root@jbdb2 ~]# rndc reload   #从主服务器同步解析数据到从服务器上

可以看到自动生成了四个解析文件。

三、测试

[root@jbdb2 ~]# dig un01.zjzfgjj.org @192.168.14.164
[root@jbdb2 ~]# dig un01.zjzfgjj.org @192.168.14.165

参考
https://blog.csdn.net/zhangym199312/article/details/78058230
https://www.cnblogs.com/liuyansheng/p/5992486.html
https://www.cnblogs.com/easonscx/p/9015194.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值