IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    DNS编程开发(8)—bind场景测试之TTL

    cjhust发表于 2015-06-24 18:46:23
    love 0

    1、测试结论

    场景1—域名不同

    $TTL 60

    b        IN  A          192.1.1.1

    $TTL 100

    a        IN  A          192.2.2.2

    备注:域名不同,则返回的是各自的TTL。

    场景2—域名相同,类型不同

    $TTL 60

    b        IN  A          192.1.1.1

    $TTL 100

    b        IN  MX       5  mx.taobao.com

    备注:域名相同,类型不同,则返回的是各自的TTL。

    场景3—域名相同,类型相同

    $TTL 60

    b        IN  A          192.1.1.1

    $TTL 100

    b        IN  A          192.2.2.2

    与

    $TTL 100

    b        IN  A          192.1.1.1

    $TTL 60

    b        IN  A          192.2.2.2

    备注:域名相同,类型相同,TTL的值为第一条rdata添加时TTL(与添加顺序有关),即上述配置dig A的TTL是不同的。

    场景4—bind作为forwarder

    image

    image

    前提:dig@server某域名某类型,返回的TTL不同;

    备注:bind将此zone的类型作为forward,@server作为forwarders,client dig时返回的TTL是最小值,与顺序无关;

    2、测试案例

    named.conf(公共配置)

    key "rndckey" {

      algorithm hmac-md5;

      secret "QFbp0H8FsqaD+Oct6TYYlg==";

    };

     

     

    controls {

      inet 127.0.0.1 port 953

      allow { 127.0.0.1; } keys { "rndckey"; };

    };

     

     

    logging {

       channel query_log {

            file "/home/jie.cj/named/logs/namequery.log"    versions 3 size 20m;

            severity        info;

            print-time        yes;

            print-category  yes;

       };

     

       category queries {

            query_log;

       };

     

       channel update_log {

            file "/home/jie.cj/named/logs/nameupdate.log"   versions 3 size 5m;

            severity        info;

            print-time        yes;

            print-category  yes;

       };

     

       category update {

            update_log;

       };

     

       channel general_log {

            file "/home/jie.cj/named/logs/namegeneral.log"  versions 3 size 5m;

            severity        info;

            print-time        yes;

            print-category  yes;

       };

     

       category general {

            general_log;

       };

    };

     

     

    options {

      recursion no;

      directory "/home/jie.cj/named/zones/";                  

      pid-file "named.pid"; 

    };

     

     

    zone "." IN {

      type hint;

      file "named.root";

    };

     

     

    zone "test.com" IN {

      type master;

      file "test.zone";

      allow-update { none; };

    };

    3、测试场景

    场景1—域名不同

    $TTL 200

    @   IN SOA  test.com.  root.test.com. (

     

                               1053891162

                                 3H

                                15M

                                 1W

                                 1D )

     

    @        IN  NS         dns.test.com.

    dns      IN  A          10.1.1.1

    $TTL 60

    b        IN  A          192.1.1.1

    $TTL 100

    a        IN  A          192.2.2.2

    image

    image

    备注:域名不同,则返回的是各自的TTL。

    场景2—域名相同,类型不同

    $TTL 200

    @   IN SOA  test.com.  root.test.com. (

     

                               1053891162

                                 3H

                                15M

                                 1W

                                 1D )

     

    @        IN  NS         dns.test.com.

    dns      IN  A          10.1.1.1

    $TTL 60

    b        IN  A          192.1.1.1

    $TTL 100

    b        IN  MX       5  mx.taobao.com

    image

    image

    备注:域名相同,类型不同,则返回的是各自的TTL。

    场景3—域名相同,类型相同

    $TTL 200

    @   IN SOA  test.com.  root.test.com. (

     

                               1053891162

                                 3H

                                15M

                                 1W

                                 1D )

     

    @        IN  NS         dns.test.com.

    dns      IN  A          10.1.1.1

    $TTL 60

    b        IN  A          192.1.1.1

    $TTL 100

    b        IN  A          192.2.2.2

    image

     

    $TTL 200

    @   IN SOA  test.com.  root.test.com. (

     

                               1053891162

                                 3H

                                15M

                                 1W

                                 1D )

     

    @        IN  NS         dns.test.com.

    dns      IN  A          10.1.1.1

    $TTL 100

    b        IN  A          192.1.1.1

    $TTL 60

    b        IN  A          192.2.2.2

     

    image

    备注:在相同域名、相同类型的情况下,bind会以第一条记录的TTL为准(即与添加顺序有关),后面新添加的记录不会覆盖之前的TTL。

    场景4—bind作为forwarder

    options {

    #  recursion no;

      directory "/home/jie.cj/named/zones/";                  

      pid-file "named.pid"; 

    };

     

    zone "gds.1699.com" IN {

      type forward;

      forwarders {1.1.1.1;};

    };

    备注:forwarder需要将递归选项打开;

     

    (1)dig @1.1.1.1 test-1-115.adns.com.gds.1699.com

    image

    (2)dig @bind_ip test-1-115.adns.com.gds.1699.com

    image

    备注:猜测bind将TTL值做了处理,即选择最小的TTL。

     

    (3)dig @1.1.1.1 test-1-115.adns.com.gds.1699.com

    image

    (4)dig @bind_ip test-1-115.adns.com.gds.1699.com

    image

    备注:猜测正确,即bind作为forwarder时,会选取最小的TTL作为统一值。

     

    (5)递归问题

    Question:已经有forwarder,为什么还要去递归?(通过抓包,可以看到bind不仅会向forwarder发送查询请求,也会向root去递归)

    Answer:

    zone "gds.1699.com" IN {

      type forward;

      forward only;    #设置forward only后,只会向1.1.1.1发送查询请求,而不会向root递归

      forwarders {1.1.1.1;};

    };

     

     


沪ICP备19023445号-2号
友情链接