首页 > 代码库 > DNS及bind详解

DNS及bind详解


三台测试服务器:mail、www、dns

mail,192.168.1.29

www , 192.168.1.28

dns , 192.168.1.27

pop --> mail

ftp --> www


1、安装bind

yum install bind


2、把原配置文件打成bak

[root@localhost ~]# mv /etc/named.conf /etc/named.conf.bak


3、重新建主配置文件named.conf

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


options {
        directory "/var/named";
};

zone "." IN {
         type hint;
         file "named.ca";
};

zone "localhost." IN {
         type master;
         file "named.localhost";
};

zone "1.0.0.127.in-addr.arpa." IN {
         type master;
         file "named.loopback";
};

4、修改/etc/named.conf的属主属组和权限


[root@localhost ~]# chown root:named /etc/named.conf


[root@localhost ~]# chmod 640 /etc/named.conf


5、检查配置文件是否有语法错误


[root@localhost ~]# service named configtest
zone localhost/IN: loaded serial 0
zone 1.0.0.127.in-addr.arpa/IN: loaded serial 0

6、启动named服务


[root@localhost ~]# service named start
Generating /etc/rndc.key:                                  [确定]
启动 named:                                               [确定]

7、添加区域到配置文件中/etc/named.conf


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


8、创建区域文件shamereedwine.com.zone


cd  /var/named目录中


vim shamereedwine.com.zone


$TTL 600
@                    IN                 SOA           dns.shamereedwine.com.  admin.shamereedwine.com.  (
                                                      2017061801
                                                      2H
                                                      10M
                                                      7D
                                                      1D )
@                    IN                 NS            dns
@                    IN                 MX   10       mail
dns                  IN                 A             192.168.1.27
mail                 IN                 A             192.168.1.29
www                  IN                 A             192.168.1.28
pop                  IN                 CNAME         mail
ftp                  IN                 CNAME         www

9、修改区域文件shamereedwine.com.zone的属组和属主


[root@localhost named]# chown root:named shamereedwine.com.zone

[root@localhost named]# chmod 640 shamereedwine.com.zone

10、检查语法是否有错误


[root@localhost named]# service named configtest
zone localhost/IN: loaded serial 0
zone 1.0.0.127.in-addr.arpa/IN: loaded serial 0
zone shamereedwine.com/IN: loaded serial 2017061801


11、重新启动named服务


[root@localhost named]# service named restart
停止 named:.                                              [确定]
启动 named:                                               [确定]

12、使用dig命令测试dns解析


[root@localhost named]# dig -t NS shamereedwine.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> -t NS shamereedwine.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52704
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; QUESTION SECTION:
;shamereedwine.com.        IN    NS

;; ANSWER SECTION:
shamereedwine.com.    600    IN    NS    dns.shamereedwine.com.

;; ADDITIONAL SECTION:
dns.shamereedwine.com.    600    IN    A    192.168.1.27

;; Query time: 1 msec
;; SERVER: 192.168.1.27#53(192.168.1.27)
;; WHEN: Mon Jun 19 07:49:56 2017
;; MSG SIZE  rcvd: 69

13、使用dig命令解析pop.shamereedwine.com


[root@localhost named]# dig -t A pop.shamereedwine.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2 <<>> -t A pop.shamereedwine.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16672
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;pop.shamereedwine.com.        IN    A

;; ANSWER SECTION:
pop.shamereedwine.com.    600    IN    CNAME    mail.shamereedwine.com.
mail.shamereedwine.com.    600    IN    A    192.168.1.29


;; AUTHORITY SECTION:
shamereedwine.com.    600    IN    NS    dns.shamereedwine.com.

;; ADDITIONAL SECTION:
dns.shamereedwine.com.    600    IN    A    192.168.1.27

;; Query time: 1 msec
;; SERVER: 192.168.1.27#53(192.168.1.27)
;; WHEN: Mon Jun 19 07:54:39 2017
;; MSG SIZE  rcvd: 108




本文出自 “服务器运维” 博客,请务必保留此出处http://shamereedwine.blog.51cto.com/5476890/1939591

DNS及bind详解