zoukankan      html  css  js  c++  java
  • BIND9配置文件详解模板[转载]

    在CU上看到了一篇关于BIND9配置文件详解的文章,感觉不错,现转载了分享一下。

    //named.conf 注释说明 by shellyxz@163.com
    // 此文件对bind9的默认配置文件的说明
    //options 语句指定全局选项,对于某些特定区域服务器,某些选项以后可能会被覆盖。bind9的选项超过100个.....
    options
    {
            // Those options should be used carefully because they disable port
            // randomization
            // query-source    port 53;        
            // query-source-v6 port 53;
            
            // Put files that named is allowed to write in the data/ directory:
            directory "/var/named"; //让named程序cd到指定的目录。任何输出文件也写入这个目录中
            dump-file                 "data/cache_dump.db";//数据库路径,rndc dumpdb命令用到
            statistics-file         "data/named_stats.txt";//服务器统计信息文件的路径,rndc stats使用
            memstatistics-file         "data/named_mem_stats.txt";//每次访问的使用的内存信息

    };
    //日志处理方式配置,bind9有很强大的日志处理能力,可以满足不同用户的要求,具体要参考相关资料
    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 {  //通道,消息能去的地方:syslog、文件或者/dev/null,这儿是bind中预先
                                     //定义的default_debug通道,日志记录到named.run文件中,严重性为dynamic
                    file "data/named.run";//文件通道
                    severity dynamic;//严重性,也就是syslog中的级别
                    print-category   yes;//不同的print选项增加或者减少消息前缀
                    print-severity   yes;//增加严重性前缀
            };        
    };
    //
    //
    //view语句用于创建分离式DNS(split DNS),view将一个用于控制哪些客户能看到哪个view的
    //访问列表,用于view中所有区的一些选项,最后还有区本身打包一起。语法如下:
    // view view-name {
    //         match-clients { address_match_list };
    //         view_optionl;.....
    //         zone_statement;....
    //    };
    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-clients 后面所给的是address_match_list,也就是访问控制列表(说明在这可以引用acl)
            //有4个表是预先定义的:
            //any  #所有主机
            //localnets  #本地上所有主机
            //localhost  #机器本身
            //none       #没有任何主机
            //总结:!!!在不同的view中,这是个很关键的位置,控制了不同的机器的查询(当然还有其他选项配合使用!!
    ########################################################################################################
            match-destinations        { localhost; };
            recursion yes;      // 运行递归查询
            # all views must contain the root hints zone:
            include "/etc/named.root.hints";
    //“hint”是一个列出根域(".")服务器的DNS记录的集合,可以使用以下方法生成
    //dig @f.root-servers.net . ns > named.root.hints
    //dig . ns > 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" //内部view
    {
    /* 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; };
            //由于是内部view,所以是默认是localnets,也可以自己定义哪些主机可以访问,格式如下:
            //match-clients     { 192.168.0.0/16; 206.168.198.192/28; };
            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;//区的类型,有:master(主)、slave(从)、stub(存根)、delegation-only(仅授权)
                                //master:区的主服务器,必须在声明master区时提供一条file语句,文件是DNS资源记录的集合
                                //slvae:区的从服务器,正常情况下从服务器保留区数据库的一个完整副本
                                //stub:也是从服务器,但是和slave的区别是,只传送NS记录。
                    file "my.internal.zone.db";//dns数据文件
    #############################################################################################################
    //当然这还有很多选项可以选择,选项的含义都很简单,从语义上可以看
    //allow-query { address_mathc_list }; [any]   
    //allow-transfer { address_match_list }; [any] 
    //allow-update { address_match_list }; [none] 
    //如果一个区用于动态更新,就会出现上面这个选项,列表说明可以发生更新的主机,动态更新仅适用于master区。动态更
    //新的概念另看其他资料。大体上是针对动态ip做的处理,bind让DHCP守护进程通知BIND它所做的地址分配情况,因而可随时
    //更新DNS数据库的内容,具体情况查阅相关资料
    ##############################################################################################################
            };
            zone "my.slave.internal.zone" { //区从服务器
                    type slave;
                    file "slaves/my.slave.internal.zone.db";
                    masters { /* put master nameserver IPs here */ 127.0.0.1; } ; 
                    //masters语句列出了一台或则多台机器的ip地址,可以从这些ip地址得到区数据库。
                    // 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语句定义了用于某个特定服务器身份验证的有名字的加密密钥。
    key ddns_key //ddns_key这是个key-id,key_id必须在首次使用之前在named.conf文件中定义
    {
            algorithm hmac-md5; //加密算法,TSIG有多种加密算法,但是bind只实现了hmac-md5一种
            secret "use /usr/sbin/dns-keygen to generate TSIG keys";
            //用dns-keygen产生的TSIG(transaction signature)事物签名。TSGI只用于服务器之间的消息和响应上,
            //而不用在服务器和解析器之间。事物签名验证双方的身份,证实数据没有被篡改过。
            
    };
    ##############################################################################################
    //DNS安全的策略有访问控制列表、TSIG,还有DNSSEC,它是对DNS的扩展,使用公钥加密,对区数据的来源
    //进行验证,并验证完整性。DNSSEC依赖于一条信任链:根服务器提供顶级域的有效信息,顶级域提供二级
    //域的有效信息,以此类推。DNSSEC的配置说明如下:
    //trusted-keys语句用于实现RFC2535中规定的DNSSEC安全机制。该语句的每一项都是一个5元组,标识出与
    //该域的域名服务器进行安全通信所需的域名、标志、协议、算法和密钥。
    // trusted-keys{
    //       domain flags protol algorithm key;
    //       domain flags protol algorithm key;
    //             ....
    //              }
    ##############################################################################################
    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                { any; }; 
            //这是外部view,所以允许所有主机查询
            match-destinations        { any; };

            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

            allow-query-cache { none; };//控制了查找缓存数据和根服务器线索文件的主机
            // Disable lookups for any cached data and root hints

            //每个view都必须包含线索文件,怎么得到线索文件上面有说明
            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.conf原始配置文件的全部内容,当然要满足特定环境的需要还有很多东西需要改变或者添加                                                                                           
    # 下面做些总结:                                                                                
    # 1.DNS服务器有各种工作方式,缓存域名、转发、从域名、主域名、分离域名等方式,还可以配合起来使用;    
    # 2.split DNS的实现原理:通过view语句match-clients、match-destination等选项实现;                   
    # 3.每个view中必须包含hints文件,hints文件可以通过 dig @root-server . ns > file 的方式实现;     
    # 4.注意区数据文件里边的各种RR,记得在更新区数据文件后,一定提高SOA记录里serial number值; 

    ################################################################

    文章转自:http://bbs.chinaunix.net/viewthread.php?tid=2293026

  • 相关阅读:
    ABB机器人 带参数例行程序
    面试题10- I:斐波那契数列(C++)
    面试题39:数组中出现次数超过一半的数字(C++)
    面试题50:第一个只出现一次的字符(C++)
    第八部分 表的基本操作
    第七部分 表中数据的基本操作
    面试题18:删除链表的节点(C++)
    面试题35:复杂链表的复制(C++)
    面试题54:二叉搜索树的第k大节点(C++)
    面试题62:圆圈中最后剩下的数字(C++)
  • 原文地址:https://www.cnblogs.com/y724107196/p/4020830.html
Copyright © 2011-2022 走看看