w_0012.gifDNS域名服务基础


1、DNS解析的作用


正向解析:根据主机名称(域名)查找对应IP地址,这是最常用的、最基础的功能。


反向解析:根据地址查找其对应的主机名称。


2、DNS服务器的类型


缓存域名服务器:向其他DNS服务器查询,获得域名->IP地址记录


缓存查询结果,提高重复查询的速度


主域名服务器:特定DNS区域的官方服务器,具有唯一性;


负责维护该区域内所有的域名->IP地址记录


从域名服务器:也称为辅助域名服务器;


其他维护的域名->IP地址记录取决于主域服务器


3、BIND域名服务


(1)BIND服务器端程序


主要执行程序:/usr/sbin/named


服务脚本:/etc/init.d/named


默认端口:TCP/UDP 53


(2)虚拟根环境/var/named/chroot


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


区域数据文件:/var/named/..


4、type关键字定义了区域类型


master:主区域


slave:从区域


hint:根区域


forward:转发区域


named-checkconf 工具


named-checkconf named.conf检查配置文件


5、检查named.conf语法


named-chekconf工具


格式:named-chekconf [-Z] [配置文件]


[root@localhost ~]# cd /var/named/chroot/etc/


[root@ser1 etc]# named-checkconf named.conf  //检测语法,无错误无输出


6、区域数据文件解析


(1)全局TTL配置项及SOA记录


$TTL(Time To Live ,生存时间)


SOA (授权信息开始)


分号“;”开始的部分表示注释


@       IN      SOA     localhost.root.localhost.  (


(区域名)(区域管理邮箱)


……



NS,域名服务器记录

MX,邮件交换记录


A,地址记录,用在正向解析区域


CNAME,别名记录


PTR,指针记录,用在反向解析区域


t_0006.gif实验一:搭建主DNS服务器


tarena.com


www.tarena.com192.168.10.11


bbs.tarena.com192.168.10.12


blog是bbs别名


1、安装软件包


[root@localhost ~]# rpm -q bind bind-chroot caching-nameserver


package bind is not installed


package bind-chroot is not installed


package caching-nameserver is not installed


[root@localhost ~]# yum -y install bind bind-chroot caching-


nameserver


2、修改主配置文件


[root@localhost ~]# cd /var/named/chroot/etc/


[root@localhost etc]# cp -p named.caching-nameserver.conf  named.conf


[root@localhost etc]# vim named.conf


...


15 listen-on port 53 { 192.168.10.10; };   //监听端口和地址


...


27 allow-query     { any; };           //允许所有客户机查询


28 allow-query-cache { any; };


...


37  match-clients      { any; };           //允许所有用户


38  match-destinations { any; };          


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


...


51 zone "tarena.com" IN {                    //定义正向区域


52         type master;                     //区域类型


53         file "tarena.com.zone";          //区域数据文件


54 };


56 zone "10.168.192.in-addr.arpa" IN {        //定义反向区域


57         type master;                     //主区域


58         file "tarena.com.arpa";


59 };


[root@ser1 etc]# named-checkconf named.conf //检测语法,无错误无输出


3、修改数据库文件


[root@localhost etc]# cd /var/named/chroot/var/named/


[root@localhost named]# cp -p named.local tarena.com.zone


[root@localhost named]# cp -p named.local tarena.com.arpa


[root@localhost named]# cat tarena.com.zone


$TTL    86400


@       IN      SOA     localhost. root.localhost.  (


                                     1997022700 ; Serial


                                     28800      ; Refresh


                                     14400      ; Retry


                                     3600000    ; Expire


                                     86400 )    ; Minimum


       IN      NS      dns1.tarena.com.


dns1    IN      A       192.168.10.10


www     IN      A       192.168.10.11


bbs     IN      A       192.168.10.12


blog    IN      CNAME   bbs


[root@localhost named]# cat tarena.com.arpa


$TTL    86400


@       IN      SOA     localhost. root.localhost.  (


                                     1997022700 ; Serial


                                     28800      ; Refresh


                                     14400      ; Retry


                                     3600000    ; Expire


                                     86400 )    ; Minimum


       IN      NS      dns1.tarena.com.


10      IN      PTR     dns1.tarena.com.


11      IN      PTR     www.tarena.com.


12      IN      PTR     bbs.tarena.com.


[root@localhost named]# named-checkzone tarena.com  tarena.com.zone


zone tarena.com/IN: loaded serial 1997022700


OK


[root@localhost named]# named-checkzone tarena.com  tarena.com.arpa


zone tarena.com/IN: loaded serial 1997022700


OK


4、启动服务


[root@localhost named]# service named restart


[root@localhost named]# chkconfig named on


5、测试


把DNS指向服务器


nslookup


如在CP时没有加-p选项,那么服务将不能启动或无法测试,需将组改成named方可


[root@localhost etc]# chgrp named named.conf


[root@localhost etc]# ls -l named.conf


-rw-r----- 1 root named 1210 04-18 10:33 named.conf


[root@localhost named]# chgrp named tarena.com.zone


[root@localhost named]# chgrp named tarena.com.arpa


[root@localhost named]# ls -l tarena.com*


-rw-r----- 1 root named 520 04-18 10:29 tarena.com.arpa


-rw-r----- 1 root named 549 04-18 10:32 tarena.com.zone