DNS正向解析、反向解析、多区域、主从架构和时间同步NTP

一、DNS正向解析

1、服务端

(1)装包

yum -y installs bind-chroot  bind bind-util

(2)修改配置文件

[root@shixun2 named]# vim /etc/named.conf
……
zone "daning.com" IN {
        type master;
        file "daning.com.zone";
};

(3)创建新的地址库文件

[root@lianxi ~]# cd /var/named/

[root@lianxi named]# ls

110.168.192.zone  chroot  dynamic   named.empty      named.loopback

192.168.110.zone  data    named.ca  named.localhost  slaves

[root@lianxi named]# cp -p named.localhost  daning.com.zone
[root@shixun2 named]# vim daning.com.zone
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
daning.com.     NS      wdn
wdn             A       192.168.110.22     //DNS服务器地址
www             A       192.168.110.20     //客户端地址

(4)检查配置文件是否正确

[root@lianxi named]# named-checkconf /etc/named.conf

[root@lianxi named]# named-checkconf /etc/named.rfc1912.zones

[root@lianxi named]# named-checkzone daning.zone  daning.zone

zone daning.zone/IN: loaded serial 0

OK

[root@lianxi named]#  

(5)重启服务并测试

[root@shixun2 named]# systemctl restart named

[root@shixun2 named]# systemctl stop firewalld.service

[root@lianxi named]# netstat -lnupt | grep named

tcp        0      0 127.0.0.1:53         0.0.0.0:*           LISTEN      4194/named          

tcp        0      0 127.0.0.1:953        0.0.0.0:*           LISTEN      4194/named          

tcp6       0      0 ::1:53              :::*                LISTEN      4194/named          

tcp6       0      0 ::1:953             :::*                LISTEN      4194/named          

udp        0      0 127.0.0.1:53        0.0.0.0:*                       4194/named          

udp6       0      0 ::1:53              :::*                           4194/named          

[root@lianxi named]#

2、客户端

(1)指定DNS服务器地址

[root@shixun2 ~]# echo nameserver 192.168.110.22 > /etc/resolv.conf

(2)测试

[root@shixun2 ~]# nslookup www.daning.com

Server: 192.168.110.22

Address: 192.168.110.22#53



Name: www.daning.com

Address: 192.168.110.20

 二、反向解析

1、DNS服务器

(1)修改配置文件

[root@shixun2 named]# vim /etc/named.conf
options {
            directory    "/var/named";
            listen-on port 53 {127.0.0.1;any; };
            allow-query {localhost;any; };


[root@lianxi ~]# vim /etc/named.rfc1912.zones
……
zone "110.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.110.zone";
        allow-update { none; };
};

(2)创建新的地址库文件

[root@shixun2 named]# cp -p named.localhost 192.168.110.zone
[root@shixun2 named]# vim 192.168.110.zone
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
      NS       @
      A        127.0.0.1
      AAAA     ::1
      PTR      localhost
145   PTR      www.daning.com

​

(3)启动服务

[root@shixun2 named]# systemctl restart named

[root@shixun2 named]# systemctl stop firewalld

(4)检查

[root@shixun2 named]# named-checkconf /etc/named.conf

[root@shixun2 named]# named-checkconf /etc/named.rfc1912.zones

[root@shixun2 named]# named-checkzone 192.168.110.zone 192.168.110.zone

zone 192.168.110.zone/IN: loaded serial 0

OK

2、客户端

(1)测试

 三、DNS多区域

1、DNS服务器

(1)修改配置文件

[root@shixun2 ~]# vim /etc/named.conf

……

zone "daning.com" IN {

        type master;

        file "daning.com.zone";

};



zone "exam.com" IN {

        type master;

        file "exam.com.zone";

};

(2)创建新的地址库文件

[root@shixun2 named]# cp -p daning.com.zone exam.com.zone         

[root@shixun2 named]# vim daning.com.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
                                       0 ; serial
                                       1D ; refresh
                                       1H ; retry
                                       1W ; expire
                                       3H ) ; minimum
daning.com.     NS      wdn
wdn             A       192.168.110.22
www             A       192.168.110.20

[root@shixun2 named]# vim  exam.com.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
                                       0 ; serial
                                       1D ; refresh
                                       1H ; retry
                                       1W ; expire
                                       3H ) ; minimum
exam.com.       NS       wdn
wdn             A        192.168.110.22
www             A       192.168.110.20

(3)重启服务

[root@shixun2 named]# systemctl restart named

[root@shixun2 named]# systemctl stop firewalld

(4)检查配置文件是否正确

[root@shixun2 ~]# named-checkconf /etc/named.conf

[root@shixun2 named]# named-checkzone daning.cn.zone daning.cn.zone

zone daning.cn.zone/IN: loaded serial 0

OK

 2、客户端

(1)测试

[root@shixun2 ~]# nslookup www.daning.com
Server: 192.168.110.22
Address: 192.168.110.22#53


Name: www.daning.com
Address: 192.168.110.20



[root@shixun2 ~]# nslookup www.exam.com
Server: 192.168.110.22
Address: 192.168.110.22#53


Name: www.exam.com
Address: 192.168.110.20

 四、DNS主从架构

服务器IP地址
主服务器192.168.110.22
从服务器192.168.110.21
客户端192.168.110.20

1、主服务器

(1)修改主配置文件,指定从服务器IP地址

[root@shixun2 ~]# vim /etc/named.conf
options {
        directory       "/var/named";
        allow-transfer{192.168.110.21; };
};



zone "example.com" IN {
        type master;
        file "example.com.zone";
};

zone "sina.com" IN {
        type master;
        file "sina.com.zone";
};

 (2)修改地址库文件,进行声明从服务器

[root@shixun2 named]# vim daning.com.zone
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
daning.com.     NS      wdn
daning.com.     NS      wxb
wdn             A       192.168.110.22
wxb             A       192.168.110.21
www             A       10.20.30.40

[root@shixun2 named]# vim exam.com.zone
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
exam.com.       NS      wdn
exam.com.       NS      wxb
wdn             A       192.168.110.22
wxb             A       192.168.110.21
www             A       10.20.30.40

 (3)重启服务

[root@shixun2 named]# systemctl restart named

[root@shixun2 named]# systemctl stop firewalld.service

2、从服务器

(1)装包

[root@cong ~]# yum -y install bind bing-chroot

(2)修改主配置文件

[root@cong ~]# vim /etc/named.conf
options {
        directory       "/var/named";
};


zone "daning.com" IN {
        type slave;
        file "/var/named/slave/daning.com.zone";
        masters{192.168.110.22; };
};

zone "exam.com" IN {
        type slave;
        file "/var/named/slave/exam.com.zone";
        masters{192.168.110.22; };
};

(3)重启服务

[root@cong named]# systemctl restart named

[root@cong named]# systemctl stop firewalld.service

3、客户端 

[root@shixun2 ~]# cat /etc/resolv.conf
nameserver 192.168.110.22
nameserver 192.168.110.21

(1)主从正常

[root@shixun2 ~]# nslookup www.exam.com
Server: 192.168.110.22
Address: 192.168.110.22#53

Name: www.exam.com
Address: 10.20.30.40

[root@shixun2 ~]# nslookup www.daning.com
Server: 192.168.110.22
Address: 192.168.110.22#53

Name: www.daning.com
Address: 10.20.30.40

 

 (2)模拟宕机

主服务器关闭:[root@shixun2 named]# systemctl stop named.service

 

 五、时间同步NTP

1、装包

[root@shixun2 named]# yum -y install ntpdate.x86_64

[root@shixun2 named]# yum -y install ntp

2、修改配置文件

[root@shixun2 named]# find / -name "ntp*conf"

/etc/ntp.conf        

[root@shixun2 named]# vim /etc/ntp.conf

3、查看当前时间并启动服务

[root@shixun2 named]# systemctl restart ntpd

4、测试

[root@shixun2 named]# date -s "2023-6-9 12:23:48"

2023年 06月 09日 星期五 12:23:48 CST

[root@shixun2 named]# date

2023年 06月 09日 星期五 12:23:52 CST

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值