bind dlz view CDN配置

Standard

关于bind+dlz的基本配置请参考本站的bind dlz 安装配置(本文内容是在其完成基础上所做的修改)

vi /usr/local/bind/etc/named.conf

key "rndc-key" {
        algorithm hmac-md5;
        secret "Nd1jgIAu3cjBQm/cttGv4A==";
 };
 controls {
        inet 127.0.0.1 port 953
                allow { 127.0.0.1; } keys { "rndc-key"; };
 };
 include "/usr/local/bind/etc/cnc.ip";
 include "/usr/local/bind/etc/other.ip";
 include "/usr/local/bind/etc/view.conf";

vi /usr/local/bind/etc/view.conf

view "cnc_view" {
 
 match-clients           { CNC; };
 allow-query-cache       { none; };
 allow-recursion         { none; };
 allow-transfer          { none; };
 recursion               no;
 
 dlz "Mysql zone" {
   database "mysql
   {host=127.0.0.1 dbname=dns ssl=false port=3306 user=root pass= }
   {select zone from dns_records where zone = '%zone%' and view='CNC' limit 1}
   {select  ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"') when lower(type) = 'soa' then  concat_ws(' ', data, resp_person, serial, refresh, retry, expire, minimum) else data end as mydata from dns_records where zone = '%zone%' and host = '%record%' and view='CNC'}
   {}
   {select  ttl, type, host, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"') else data end as mydata, resp_person, serial, refresh, retry, expire, minimum from dns_records where zone = '%zone%' and view='CNC'}
   {select zone from xfr_table where zone = '%zone%' and client = '%client%' and view='CNC' limit 1}
   {update data_count set count = count + 1 where zone ='%zone%' and view='CNC'}";
 };
 
};
#yemaosheng.com
view "other_view" {
 
 match-clients           { other; };
 allow-query-cache       { none; };
 allow-recursion         { none; };
 allow-transfer          { none; };
 recursion               no;
 
 dlz "Mysql zone" {
   database "mysql
   {host=127.0.0.1 dbname=dns ssl=false port=3306 user=root pass= }
   {select zone from dns_records where zone = '%zone%' and view='other' limit 1}
   {select  ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"') when lower(type) = 'soa' then  concat_ws(' ', data, resp_person, serial, refresh, retry, expire, minimum) else data end as mydata from dns_records where zone = '%zone%' and host = '%record%' and view='other'}
   {}
   {select  ttl, type, host, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"') else data end as mydata, resp_person, serial, refresh, retry, expire, minimum from dns_records where zone = '%zone%' and view='other'}
   {select zone from xfr_table where zone = '%zone%' and client = '%client%' and view='other' limit 1}
   {update data_count set count = count + 1 where zone ='%zone%' and view='other'}";
 };
 
};

vi /usr/local/bind/etc/cnc.ip
acl “CNC” {
192.168.0.2;
};

vi /usr/local/bind/etc/other.ip
acl “other” {
192.168.0.3;
};

如何得到所需使用的IP地址段可参考使用whois3得网通 电信 铁通的IP地址段

转载请注明出处:http://yemaosheng.com

15 thoughts on “bind dlz view CDN配置

  1. jackboy

    感谢您的分享,但是我做了电信网通以后都不能正常解析,日志报错如下,请帮忙分析一下:
    #38034: no matching view in class ‘IN’

  2. jackboy

    叶大哥,上面的问题解决了,重建了表结构。
    能分享一下你这个CDN架构相关的库的表结构吗?
    你有没有比较精准的IP库啊,怎么获得精准的IP库,如果要钱,花钱从那买?

  3. jack

    感谢叶大哥的热情回答.
    select zone from xfr_table
    这个 xfr_table 表是什么结构,这个怎么多一个这样的表结构.

    这个view的数据库结,应该还多一个view字段吧?

    要是whois3抓到的IP也能存到库里就好了!

  4. sunny

    我也正在做实验,正好遇到这个问题,感谢叶老大的文章,非常不错!
    你上面提到xfr_table表,我也不明白是作什么用的。

    还有如何把whois3导出的IP文件导入到库里是很简单
    但是在view.conf里怎么样的来写让他从库里读取那些IP呢?

  5. jackboy

    叶大哥,真热心!还有个问题需要再请教一下:
    如果我把IP列表写在数据库的里的addr表里
    { 表: addr
    字段:cnc,telecom,crtc,edu,any 存取IP范围。
    }

    那我怎么在view.conf里的那个match-clients部分用SQL语句从库中去取这些IP呢?而不是从文件里读,怎么写,能写个简单的范列,或者提示一下吗!

    • 呵呵,没什么:)
      这个问题到还没想过,好像目前还没法这样做.
      IP范围的变化不算是太实时的问题,所以用个文件就行了,也没必要非转到数据库上面:)

  6. jackboy

    如何向这个表插入SOA记录呢?
    仍后set type=soa
    yemaosheng.com

    查询不正确。

    需要插入多少条SOA记录呢?

  7. dayinfinte

    我想请问一下,对于IP来源的分类,就智能通过写到配置文件的方式么,有没有在配置文件里面执行程序查找数据库的方法

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.