linux rehl 5 dns 详解3

RHEL5搭建DNS服务器实现名称解析 三
 
 
named.conf文件说明:
此文件需用户自己创建,可从/usr/share/doc/bind-9.3.3/sample/etc中复制到/var/named/chroot/etc/目录下
// Sample named.conf BIND DNS server 'named' configuration file
// for the Red Hat BIND distribution.
// See the BIND Administrator's Reference Manual (ARM) for details, in:
//   file:///usr/share/doc/bind-*/arm/Bv9ARM.html
// Also see the BIND Configuration GUI : /usr/bin/system-config-bind and
// its manual.
options
{
          /* make named use port 53 for the source of all queries, to allow
         * firewalls to block all ports except 53:
         */
          query-source    port 53;
          query-source-v6 port 53;
         
          // Put files that named is allowed to write in the data/ directory:
          directory "/var/named"; // the default  (定义Bind服务器的工作目录)
          dump-file       "data/cache_dump.db";
        statistics-file     "data/named_stats.txt";
        memstatistics-file "data/named_mem_stats.txt";
};
logging
{
/*      If you want to enable debugging, eg. using the 'rndc trace' command,
 *      named will try to write the 'named.run' file in the $directory (/var/named).
 *      By default, SELinux policy does not allow named to modify the /var/named directory,
 *      so put the default debug log file in data/ :
 */
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
// All BIND 9 zones are in a "view", which allow different zones to be served
// to different types of client addresses, and for options to be set for groups
// of zones.
//
// By default, if named.conf contains no "view" clauses, all zones are in the
// "default" view, which matches all clients.
//
// If named.conf contains any "view" clause, then all zones MUST be in a view;
// so it is recommended to start off using views to avoid having to restructure
// your configuration files in the future.
view "localhost_resolver"
{
/* This view sets up named to be a localhost resolver ( caching only nameserver ).
 * If all you want is a caching-only nameserver, then you need only define this view:
 */
          match-clients       { localhost; };                        (本地主机)
          match-destinations  { localhost; };        
                recursion yes;                                            (设置允许递归)
 
          # all views must contain the root hints zone:
          include "/etc/named.root.hints";                          (载入根服务器信息)
        /* these are zones that contain definitions for all the localhost
         * names and addresses, as recommended in RFC1912 - these names should
           * ONLY be served to localhost clients:
           */
          include "/etc/named.rfc1912.zones";
};
view "internal"                                                       (内部视图)
{
/* This view will contain zones you want to serve only to "internal" clients
   that connect via your directly attached LAN interfaces - "localnets" .
 */
          match-clients       { localnets; };                      (本地网络)
          match-destinations  { localnets; };
          recursion yes;                                 
          // all views must contain the root hints zone:
          include "/etc/named.root.hints";                
        // include "named.rfc1912.zones";                    
          // you should not serve your rfc1912 names to non-localhost clients.
          // These are your "authoritative" internal zones, and would probably
          // also be included in the "localhost_resolver" view above :
          zone "my.internal.zone" {                        
              type master;                                  
              file "my.internal.zone.db";                  
          };
          zone "my.slave.internal.zone" {
              type slave;
              file "slaves/my.slave.internal.zone.db";
              masters { /* put master nameserver IPs here */ 127.0.0.1; } ;
              // put slave zones in the slaves/ directory so named can update them
          }; 
          zone "my.ddns.internal.zone" {
              type master;
              allow-update { key ddns_key; };
              file "slaves/my.ddns.internal.zone.db";
              // put dynamically updateable zones in the slaves/ directory so named can update them
          };         
};
key ddns_key
{
          algorithm hmac-md5;
          secret "use /usr/sbin/dns-keygen to generate TSIG keys";
};
view    "external"                                                    (外部视图)
{
/* This view will contain zones you want to serve only to "external" clients
 * that have addresses that are not on your directly attached LAN interface subnets:
 */
          match-clients       { !localnets; !localhost; };
          match-destinations  { !localnets; !localhost; };
          recursion no;
          // you'd probably want to deny recursion to external clients, so you don't
        // end up providing free DNS service to all takers
          // all views must contain the root hints zone:
          include "/etc/named.root.hints";
          // These are your "authoritative" external zones, and would probably
        // contain entries for just your web and mail servers:
          zone "my.external.zone" {
              type master;
              file "my.external.zone.db";
          };
};
 
 
 
根服务器信息文件named.root:named.root文件中记录了Internet根域名服务器的名字和地址。DNS服务器在收到客户端的查询请求时,如果在本地找不到相应的数据,就会通过根服务器逐级进行查询。例如,当DNS服务器收到来自客户端查询www.bit.edu.cn的请求时,DNS服务器会首先在本地数据库中查找,如果没有找到就会向Internet的根服务器转发该请求,然后由根服务器转给cn域的DNS服务器,再由cn域的DNS服务器转给edu.cn域的DNS服务器,依此类推,直到找到能够解析www.bit.edu.cnDNS服务器。由于根域名服务器会随Internet的变化而时常发生变动,因此named.root文件应及时更新。用户可以匿名登录ftp://internic.net,下载该文件的最新版本。对于采用递归方式工作的DNS服务器,必须在每一视图中都指定根服务器信息文件
常用的配置语句选项说明:
options
服务器的全局配置选项及一些默认设置
view
定义一个视图
zone
定义一个区域
logging
指定服务器日志记录的内容和日志信息的来源
acl
定义IP地址的访问控制列表
include
加载的文件
key
指定用于识别和授权的密钥信息
server
设置服务器的参数
trusted-key
指定信任的DNSSEC加密密钥
type
定义区域的类型
file
指定一个区域文件
directory
指定区域文件的目录
forwarders
指定请求将被转发到的DNS服务器
masters
指定从服务器所使用的主服务器
allow-transfer
指定允许按受区域传送请求的主机
allow-query
指定允许进行查询的主机
notify
当主区域数据发生变化时,允许通知从服务器
controls
定义rndc命令使用的控制通道
主要配置语句的语法格式如下:
1.options语句格式:
   options  {
      directory  pathname;
      statistics-interval  number;
      forwarders { [ in-addr ; [ in-addr ; ……] ] }; 
   forward  ( only | first );
   query-source  address  *  port  53  ;
   recursion  ( yes | no);
   allow-recursion  { address-math-list };
};
directory选项用于指定域名服务器的工作目录,该目录也是区域文件的存储目录。如果没有指定任何目录,默认的工作目录就是“.”,即服务器的启动目录。指定的目录应该使用绝对路径,在其他语句中指定的相对路径都是相对于该工作目录来定义的。
statistics-interval选项用于指定域名服务器产生统计数据的时间间隔。默认情况下,域名服务器每隔一小时就将统计数据通过syslog写入默认的日志文件/var/message(调用syslogd程序写入/var/message),如果想要更改这一默认的设置,可以添加该选项并指定期望的间隔时间,系统将以此为周期记录统计资料。如果希望禁用该功能可以将值设为“0”。
forwarders选项用于将DNS服务器收到的查询请求转发到其他的域名服务器上,通常是一个远程域名服务器的IP地址列表。例如:forwarders  { 202.17.55.10 ; 203.137.15.33 ;  117.32.34.56 ; };其中相邻的IP地址都需要使用“;”分隔。如果没有指定此选项,则默认的转发列表为空,服务器不会进行转发,所有的请求都由域名服务器自己来处理。
forward选项仅当forwarders选项的转发列表不为空时才有效。此选项用于控制域名服务器的行为。如果将该选项设置为first(默认值),则域名服务器将所有请求发送到设定的转发服务器。如果转发服务器超时或无响应,则域名服务器将试图自己查找结果。如果设置成only,则域名服务器只转发所有查询请求,不会自己执行搜索。
query-source选项用于指定查询服务所使用的端口号,通常为53。防火墙一般只允许端口53上的DNS数据流,如果在两个域名服务器之间有防火墙,应将端口号设为53
recursion选项指定是否允许客户端递归查询其他域名服务器。如果希望对本地客户端的查询允许递归,但对来自外部的查询请求禁止递归,可以通过“allow-recursion”选项进行定义。allow-recursion选项可以指定一个允许执行递归查询操作的地址列表。
2.acl语句格式:
acl  acl_name  {
    address_math_list ;
};
acl即访问控制列表,定义了一个地址匹配列表。
 
 
3.server语句格式:
server  ip_addr  {
  bogus  yes|no;
  provide-ixfr  yes|no;
  request-ixfr  yes|no;
  support-ixfr  yes|no;
  edns  yes|no;
  transfers  number;
  transfer-format  one-answer|many-answers;
  keys  { key-id;key-id;……};
};
DNS服务器需要与其他许多DNS服务器进行通信,但并非所有的服务器都运行着相同版本的Bind,甚至有些DNS服务器还可能“不正常”地运行。server语句用于描述远程DNS服务器的特征。
4.key语句格式:
         key  key-id  {
algorithm  string;
secret  string;
};
key语句定义了用于服务器身份验证的加密密钥。
5.controls语句格式:
controls  {
inet  ip_addr  allow {  address_match_list  }  keys  {  key_list  };
};
controls语句规定了rndc(在Bind8中是ndc)如何控制一个正在运行的named进程。rndc可以启动和停止named,转储其状态或将其转入调试模式。
6.view语句格式:
view  view-name  {
      match-clients  {  address_match_list  };
view_option;
zone_statement;
};
view语句可以根据客户端地址进行域名解析,使不同的客户端使用同一DNS服务器对同一地址进行解析,却可以得到不同的解析结果。view语句使用一个控制列表对客户端能看到哪个视图进行控制。
7.include语句格式:
 include语句用于加载根区域。当DNS服务器处理递归查询时,如果本地区域文件不能对查询进行解析,就会转到根DNS服务器进行查询,所以在主配置文件named.conf中需要指定根区域,而且每一个view都必须包含根区域。例如在localhost_resolver视图中加载根区域,过程如下所示:
  view  localhost_resolver
   {
 /*This view sets up named to be localhost resolver (caching only nameserver).
  *If all you want is a caching-only nameserver, then you need only define this view: */
      match-clients       {  localhost; };
      match-destinations  {  localhost; };
      recursion  yes;
      #all views must contain the root hints zone:
      include  /etc/named.root.hints;
};
8.zone语句格式:
zone语句是named.conf文件的核心部分,用于在域名系统中设置所使用的区域(分为正向解析区域和反向解析区域),并为每个区域设置适当的选项。zone语名的格式如下
 zone  domain_name  {
      type  master ----- 表示区域的类型为主服务器;
      file  path;   ----- 设置此区域的区域文件路径和文件名;
};
其中“file”用于指定与所定义区域相关的区哉配置文件,“type”用于指定区域的类型。
Bind可以使用的区域类型及其说明如下表
类型
说明
master
主DNS区域
slave
从DNS区域,从属于主DNS区域
forward
将任何解析请求转发给其他的DNS服务器
stub
与从DNS区域类似,但只保留DNS服务器的名称
hint
根域名服务器
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值