hosts文件 -->..."/>
溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

DNS查詢過程及DNS服務(wù)器簡(jiǎn)單搭建

發(fā)布時(shí)間:2020-07-12 21:12:46 來源:網(wǎng)絡(luò) 閱讀:1052 作者:春天的金縷 欄目:建站服務(wù)器

1、描述DNS查詢過程以及DNS服務(wù)器類別。

    DNS查詢過程:

    一次完整的查詢請(qǐng)求經(jīng)過的流程:

    Client--> hosts文件 --> DNS Local Cache --> DNS Server (recursion) -->

         自己負(fù)責(zé)解析的域:直接查詢數(shù)據(jù)庫并返回答案;

         不是自己負(fù)責(zé)解析域:ServerCache --> iteration(迭代)

    DNS服務(wù)器類別:

         -DNS服務(wù)器:

         DNS服務(wù)器:維護(hù)所負(fù)責(zé)解析的域數(shù)據(jù)庫的那臺(tái)服務(wù)器;讀寫操作均可進(jìn)行;

         DNS服務(wù)器:從主DNS服務(wù)器那里或其它的從DNS服務(wù)器那里“復(fù)制”一份解析庫;但只能進(jìn)行讀操作;

             “復(fù)制”操作的實(shí)施方式:

               序列號(hào):serial, 也即是數(shù)據(jù)庫的版本號(hào);主服務(wù)器數(shù)據(jù)庫內(nèi)容發(fā)生變化時(shí),其版本號(hào)遞增;

               刷新時(shí)間間隔:refresh,從服務(wù)器每多久到主服務(wù)器檢查序列號(hào)更新狀況;

               重試時(shí)間間隔:retry,從服務(wù)器從主服務(wù)器請(qǐng)求同步解析庫失敗時(shí),再次發(fā)起嘗試請(qǐng)求的時(shí)間間隔;

               過期時(shí)長(zhǎng):expire,從服務(wù)器始終聯(lián)系不到主服務(wù)器時(shí),多久之后放棄從主服務(wù)器同步數(shù)據(jù);停止提供服務(wù);

               否定答案的緩存時(shí)長(zhǎng):

2、搭建一套DNS服務(wù)器,負(fù)責(zé)解析magedu.com域名(自行設(shè)定主機(jī)名及IP

  (1)、能夠?qū)σ恍┲鳈C(jī)名進(jìn)行正向解析和逆向解析;

  (2)、對(duì)子域cdn.magedu.com進(jìn)行子域授權(quán),子域負(fù)責(zé)解析對(duì)應(yīng)子域中的主機(jī)名;

  (3)、為了保證DNS服務(wù)系統(tǒng)的高可用性,請(qǐng)?jiān)O(shè)計(jì)一套方案,并寫出詳細(xì)的實(shí)施過程

 

         首先安裝配置bind:

                   yuminstall bind -y

                   servicenamed start 

                            systemctlstart  named.servicecentos7)

                   ss-tunl |grep 53

         bind

                            主配置文件:/etc/named.conf

                                     或包含進(jìn)來其它文件;

                                               /etc/named.iscdlv.key

                                               /etc/named.rfc1912.zones

                                               /etc/named.root.key

                            析庫文件:

                                     /var/named/目錄下;

                                               一般名字為:ZONE_NAME.zone

                                              

               注意:(1) 一臺(tái)DNS服務(wù)器可同時(shí)為多個(gè)區(qū)域提供解析;

                     (2) 必須要有根區(qū)域解析庫文件:named.ca;

                     (3) 還應(yīng)該有兩個(gè)區(qū)域解析庫文件:localhost127.0.0.1的正反向解析庫;

                              正向:named.localhost

                              反向:named.loopback

A.解析一個(gè)正向區(qū)域

         1.緩存名稱服務(wù)器的配置:

         [root@localhost~]# vim /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.

         //

         //See the BIND Administrator's Reference Manual (ARM) for details about the

         //configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html

 

         options{

         //               listen-on port 53 { 127.0.0.1; };                 ###注銷本行,注銷本行,表示監(jiān)聽所有地址

         //               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     { localhost; };         ###關(guān)閉僅允許本地查詢

    

   recursion yes;

 

   // dnssec-enable yes;                         ###學(xué)習(xí)時(shí),建議關(guān)閉dnssec,DNS安全認(rèn)證

   // dnssec-validation yes;                     ###學(xué)習(xí)時(shí),建議關(guān)閉dnssec

      修改完成后檢查配置文件的語法錯(cuò)誤

          named-checkconf   [/etc/named.conf]

         [root@localhost~]# named-checkconf           

         2.定義區(qū)域

         在主配置文件中或主配置文件輔助配置文件中實(shí)現(xiàn)

         [root@localhost~]# vim /etc/named.rfc1912.zones   ###編輯配置文件,添加以下內(nèi)容

         zone"magedu.com" IN {                                                                     ###添加

       type master;

       file "magedu.com.zone";

         };

         3.建立區(qū)域數(shù)據(jù)文件(主要記錄為AAAAA記錄)

              /var/named目錄下建立區(qū)域數(shù)據(jù)文件;

[root@localhostnamed]# vim /var/named/magedu.com.zone

$TTL86400                                          ###緩存有效期86400=1

                   $ORIGINmagedu.com.                                                                   

                   @       IN     SOA     ns1.magedu.com.dnsadmin.magedu.com. (

                                     2017060601     ###序列號(hào)

                                     1H             ###刷新時(shí)間

                                     10M            ###重試時(shí)間

                                     3D             ###過期時(shí)間

                                     1D)            ###否定答案時(shí)間

                                     IN      NS     ns1

                                     IN      NS     ns2

                                     IN      MX 10  mx1

                                     IN      MX 20  mx2

                   ns1     IN     A       192.168.0.104

                   ns2     IN     A       192.168.0.105

                   mx1     IN     A       192.168.0.106

                   mx2     IN     A       192.168.0.107

                   www     IN      A      192.168.0.104

                   web     IN     CNAME   www

~    語法檢查:

                   [root@localhostnamed]# named-checkconf

                   [root@localhostnamed]# named-checkzone magedu.com /var/named/magedu.com.zone

                   zonemagedu.com/IN: loaded serial 2017060601

                   OK

           權(quán)限修改:

                   [root@localhostnamed]# chown :named /var/named/magedu.com.zone    ###修改屬組為named

                   chmodo= /var/named/magedu.com.zone                                                               ###修改其他無權(quán)限

         4.讓服務(wù)器重載配置文件和區(qū)域數(shù)據(jù)文件

                   #rndc  reload

                   #systemctl  reload  named.service

         測(cè)試:

                   dig-t A www.magedu.com @192.168.0.104

                  

同理,配置解析一個(gè)反向區(qū)域

         1.定義區(qū)域

                   在主配置文件中或主配置文件輔助配置文件中實(shí)現(xiàn);

                   [root@localhost/]# vim /etc/named.rfc1912.zones

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

                            typemaster;

                            file"192.168.0.zone";

                   };

         2.定義區(qū)域解析庫文件(主要記錄為PTR

                   [root@localhostnamed]# vim /var/named/192.168.0.zone

                   $TTL86400

                   $ORIGIN0.168.192.in-addr.arpa.

                   @       IN     SOA     ns1.magedu.com.nsadmin.magedu.com (

                                                        2017060601

                                                        1H

                                                        10M

                                                        3D

                                                        1D)

                                     IN      NS     ns1.magedu.com.

                   104     IN     PTR     ns1.magedu.com.

                   105     IN     PTR     ns2.magedu.com.

                   106     IN     PTR     mx1.magedu.com.

                   107     IN     PTR     mx2.magedu.com.

                   104     IN     PTR     www.magedu.com.

 

                   權(quán)限修改:    

                   [root@localhostnamed]# chgrp named /var/named/192.168.0.zone

                   [root@localhostnamed]# chmod o= /var/named/192.168.0.zone

                   語法檢查:

                   [root@localhostnamed]# named-checkconf

                   [root@localhostnamed]# named-checkzone 0.168.192.in-addr.arpa /var/named/192.168.0.zone

                   zone0.168.192.in-addr.arpa/IN: loaded serial 2017060601

                   OK

        

                   #rndc  reload

                   #systemctl  reload  named.service

         3.讓服務(wù)器重載配置文件和區(qū)域數(shù)據(jù)文件

                   #rndc  reload

                   #systemctl  reload  named.service

         測(cè)試;

         dig-x 192.168.0.104 @192.168.0.104

        

B.子域授權(quán)

         1.對(duì)magedu.com解析庫添加子域。

                   [root@localhost~]# vim /var/named/magedu.com.zone

                   $TTL86400

                   $ORIGINmagedu.com.

                   @       IN     SOA     ns1.magedu.com.dnsadmin.magedu.com. (

                                     2017060612

                                     1H

                                     10M

                                     3D

                                     1D)

                                     IN      NS     ns1

                                     IN      NS     ns2

                                     IN      MX 10  mx1

                                     IN      MX 20  mx2

                   ns1     IN     A       192.168.0.104

                   ns2     IN     A       192.168.0.150

                   mx1     IN     A       192.168.0.106

                   mx2     IN     A       192.168.0.107

                   www     IN     A       192.168.0.104

                   web     IN     CNAME   www

                   pop3    IN     A       192.168.0.108

                   cdn     IN     NS      ns1.cdn                                                   ###添加子域

                   cdn     IN     NS      ns2.cdn                                                   ###添加子域

                   ns1.cdnIN      A       192.168.0.103                                ###添加A記錄

                   ns2.cdnIN      A       192.168.0.155                                ###添加A記錄

         2.對(duì)子域服務(wù)器安裝bind并改配置文件及添加解析庫。

                   [root@localhost~]# yum install bind -y                              ###子域服務(wù)器安裝

                   [root@localhost~]# vim /etc/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-onport 53 { 127.0.0.1; 192.168.0.103; };      ###添加與外部通信主機(jī)地址

                                     listen-on-v6port 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     { localhost; };                                                      ###關(guān)閉僅允許本地查詢

                                     recursionyes;

 

                                     dnssec-enableno;             ###改為no

                                     dnssec-validationno;       ###改為no

                                     .......

                   [root@localhost~]# service named start

                   Generating/etc/rndc.key:                                 [確定]

                   啟動(dòng) named   

                   [root@localhost~]# vim /etc/named.rfc1912.zones                       ###編輯配置文件添加解析庫

                   zone"cdn.magedu.com" IN {

       type master;

       file "cdn.magedu.com.zone";

                   };

       [root@localhost ~]# vim /var/named/cdn.magedu.com.zone                 ###編輯解析庫數(shù)據(jù)

                   $TTL3600

                   $ORIGINcdn.magedu.com.

                   @       IN     SOA     ns1.cdn.magedu.com.     nsadmin.cdn.magedu.com. (

                                                        2017060601

                                                        1H

                                                        10M

                                                        1D

                                                        2H)

                                     IN      NS     ns1

                   ns1     IN     A       192.168.0.103

                   www     IN     A       192.168.0.10                  

                   [root@localhost~]# chgrp named /var/named/cdn.magedu.com.zone ###修改屬組為named

                   [root@localhost~]# chmod o= /var/named/cdn.magedu.com.zone          ###修改其他無權(quán)限

                   [root@localhost~]# rndc reload

                   serverreload successful

                   測(cè)試使用dig

                   [root@localhost~]# dig -t A www.cdn.magedu.com @192.168.0.103

                   定義轉(zhuǎn)發(fā)

                   [root@localhost~]# vim /etc/named.rfc1912.zones                                  ###編輯配置文件增加區(qū)域轉(zhuǎn)發(fā)

                   zone"magedu.com" IN {

       type forward;                                                                                                                  ###定義轉(zhuǎn)發(fā)

       forward only;                                                                                                                   ###只轉(zhuǎn)發(fā)                                                                                                             

       forwarders { 192.168.0.104; 192.168.0.150; };

                   };

                   [root@localhost~]# named-checkconf                                                                    ###檢查

                   [root@localhost~]# rndc reload                                                                                ###重載

                   [root@localhost~]# dig -t A www,magedu.com @192.168.0.103                   ###測(cè)試子域解析父域

                  

                   ;<<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> -tA www.magedu.com @192.168.0.103

                   ;;global options: +cmd

                   ;;Got answer:

                   ;;->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56294

                   ;;flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2

 

                   ;;QUESTION SECTION:

                   ;www.magedu.com.                           IN     A

 

                   ;;ANSWER SECTION:

                   www.magedu.com.                   86400       IN     A       192.168.0.110

 

                   ;;AUTHORITY SECTION:

                   magedu.com.           86400       IN     NS    ns1.magedu.com.

                   magedu.com.           86400       IN     NS    ns2.magedu.com.

 

                   ;;ADDITIONAL SECTION:

                   ns1.magedu.com.             86400       IN     A       192.168.0.104

                   ns2.magedu.com.             86400       IN     A       192.168.0.150

 

                   ;;Query time: 4 msec

                   ;;SERVER: 192.168.0.103#53(192.168.0.103)

                   ;;WHEN: Thu Jun  8 20:50:31 2017

                   ;;MSG SIZE  rcvd: 116

C.全局轉(zhuǎn)發(fā):針對(duì)凡本地沒有通過zone定義的區(qū)域查詢請(qǐng)求,通通轉(zhuǎn)給某轉(zhuǎn)發(fā)器;

                                     options{

                                               ......

                                               forward  {only|first};

                                               forwarders  { SERVER_IP; };

                                               .....

                                      };

主從同步:

         從服務(wù)器配置與主服務(wù)器配置安裝相同:

         1.[root@localhost~]# yum install bind -y                 ###安裝

         2.編輯/etc/named.conf文件,與前面安裝一致

         3.[root@localhost~]# vim /etc/named.rfc1912.zones          ###編輯添加從服務(wù)

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

       type slave;                                                                                            ###類型為從服務(wù)器

       file "slaves/192.168.0.zone";

       masters { 192.168.0.104; };                                                   ###主服務(wù)器地址

                   };

         4.在主服務(wù)器解析文件/var/named/magedu.zone中新增NS ,NS記錄有個(gè)A地址為從服務(wù)器地址。

         主服務(wù)器 rndcreload

         5.從服務(wù)器檢查配置文件并重啟服務(wù)  systemctl restartnamed.service

         6.服務(wù)啟動(dòng)后,會(huì)在/var/named/slaves/自動(dòng)添加magedu.com.zone文件

         主從配置完成

         注意:時(shí)間需同步   ntpdate命令


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI