suchasplus
作家
作家
  • 铜币16枚
  • 威望11点
  • 贡献值1点
阅读:3446回复:1

基于debian和bind9的动态域名解析

楼主#
更多 发布于:2007-11-16 16:16
硬件环境: Dell Poweredge 2950 XEON 5110 @1.60GHZ  双核x2  2.00GBmem 73GB
软件环境: Debian Etch 4.0r1, Bind 9.3.4
NameServer: NS已经在国内上注册了,但是由于伟大的GFW,NSrecord没法在Internic上面查到。
实现方式:Bind的VIEW功能
前提条件:bind安装OK,没有安装请直接apt-get install bind9
目标:因为网站的域名解析已经到了自己的手里,那么自然由我们自己的NS来解析。我们对web和p2p root& tracker进行镜像,通过分析client来访的IP来源,向其返回最快的镜像,以期获得最快的速度。
下面开始详细的说说实现过程:
bind9已经安装好了,then

shell> cd /etc/bind/
shell> mv named.conf named.conf.default
shell> mkdir acl
shell> mkdir -p master/{CNC,CTC,CERNET}
shell> cd acl
shell> touch CERNET.acl CNC.acl CTC.acl
shell> cd ../master
shell> touch CNC.def CTC.def CERNET.def

OK~

shell> pwd
shell> /etc/bind
shell> vim named.conf
然后把下面的代码copy进去,然后:wq保存退出
/////////////////////////////////////////////////////////
////////         Start Here        
//Aptitude DNS
//Copyright www.renwenyue.com
//Powered by suchasplus
//Modified @ 20071113


include "/etc/bind/named.conf.options";

//import CNC/CTC/CERNET's ACL
include "/etc/bind/acl/CNC.acl";
include "/etc/bind/acl/CTC.acl";
include "/etc/bind/acl/CERNET.acl";


//View Of CTC
view "view_CTC" {

 match-clients { CTC; };
 zone "." {
         type hint;
         file "/etc/bind/db.root";
 };

 zone "localhost" {
        type master;
         file "/etc/bind/db.local";
 };

 zone "127.in-addr.arpa" {
  type master;
         file "/etc/bind/db.127";
 };

 zone "0.in-addr.arpa" {
         type master;
         file "/etc/bind/db.0";
 };

 zone "255.in-addr.arpa" {
         type master;
         file "/etc/bind/db.255";
 };
 include "/etc/bind/master/CTC.def";
};

//View Of CNC
view "view_CNC" {

 match-clients { CNC; };
 zone "." {
         type hint;
         file "/etc/bind/db.root";
 };

 zone "localhost" {
        type master;
         file "/etc/bind/db.local";
 };

 zone "127.in-addr.arpa" {
  type master;
         file "/etc/bind/db.127";
 };

 zone "0.in-addr.arpa" {
         type master;
         file "/etc/bind/db.0";
 };

 zone "255.in-addr.arpa" {
         type master;
         file "/etc/bind/db.255";
 };
 include "/etc/bind/master/CNC.def";
};

//View Of CERNET
view "view_CERNET" {

 match-clients { CERNET; };
 zone "." {
         type hint;
         file "/etc/bind/db.root";
 };

 zone "localhost" {
        type master;
         file "/etc/bind/db.local";
 };

 zone "127.in-addr.arpa" {
  type master;
         file "/etc/bind/db.127";
 };

 zone "0.in-addr.arpa" {
         type master;
         file "/etc/bind/db.0";
 };

 zone "255.in-addr.arpa" {
         type master;
         file "/etc/bind/db.255";
 };
 include "/etc/bind/master/CERNET.def";
};

//View Of OtherIP => FELLOW CTC IP LIST
view "view_any" {

 match-clients { any; };
 zone "." {
         type hint;
         file "/etc/bind/db.root";
 };

 zone "localhost" {
        type master;
         file "/etc/bind/db.local";
 };

 zone "127.in-addr.arpa" {
  type master;
         file "/etc/bind/db.127";
 };

 zone "0.in-addr.arpa" {
         type master;
         file "/etc/bind/db.0";
 };

 zone "255.in-addr.arpa" {
         type master;
         file "/etc/bind/db.255";
 };
 include "/etc/bind/master/CTC.def";
};

include "/etc/bind/named.conf.local";

////////End Here

 

然后去修改/etc/bind/master下面的三个def文件
以CERNET.def为例
内容为:

zone "example.com" {
        type master;
        file "/etc/bind/master/CERNET/db.example.com";
};

保存退出,剩下的CNC.def & CTC.def依此类推,只需要修改file中的路径

然后就去CNC/CTC/CERNET添加相关解析文件,如db.example.com,格式在网上有很多,可以参考 GNU/Linux 高级网络应用服务指南,就是这本书不太好找。

最后去修改/etc/bind/acl中的三个acl(AccessControlList)文件
格式为:
acl "CERNET" {
123.123.0.0/16;
};
注意除了acl "CERNET"行外,行末都要加分号,IP段必须是mask-mode

ok,到此就配置完毕了.
shell> /usr/sbin/named -gc /etc/bind/named.conf &
启动named并显示相关启动信息
shell> nslookup
> server localhost
> www.example.com
blablabla
如果nslookup查找不到相关的域名=>IP信息,请检查你的解析文件

至此一切ok

缺点:
客戶端通過DNS解析出來的我們網站的IP,不是由客戶端所在IP段決定,而是由其設定的DNS所決定的。
客户端(包括b/s)是从他自身设置的DNS中取得数据,而不是直接从我们的NS服务器上取数据。
客户端第一次可能会从我们的NS中取得数据,因为他的服务器没有记录或者没有更新。但是flushdns后他会从他的上级DNS取数据,那时上级DNS已经获得我们的DNS数据。
由于我们是根据来访IP去发送相关解析数据的,那么客户端解析出来的IP基本是由其上级DNS决定的


原文地址: http://www.renwenyue.com/2007/11/smartdns-cdn-howto.html
The history of these days will be written in blood... By crushing the armies of our enemy, by seizing the weapons they thought to turn against us, we were fighting for our very existence!
0000
作家
作家
  • 铜币143枚
  • 威望34点
  • 贡献值1点
1C#
发布于:2007-11-16 20:28
Re:基于debian和bind9的动态域名解析
还以为是ADSL那个动态。。。
.--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/
游客

返回顶部