架构根据电信、网通用户自动解析不同IP的DNS服务器

注:已经提供了免费的DNS解析服务。并且VERYCD已经在使用了。地址:http://www.dnspod.com

/*
* 架构根据电信、网通用户自动解析不同IP的DNS服务器
* 本文介绍了如何让DNS服务器根据用户的IP地址解析出不同的镜像服务器IP

* 版本: 1.1.0
* 作者: 声仔(奶罩)
* 网站: http://wuhongsheng.com
* 版权: (C) 1999-2006 wuhongsheng.com
* 修订: 2006-01-19 23:13
* 原始出处: http://wuhongsheng.com/blog/?p=235
*/

本文档基于FreeBSD、BIND平台,Win用户请回避,没有FreeBSD基础的用户请回避。Linux或者其他Unix用户可以作为参考文档。

修订记录:
2006-01-19 修订了部分网通用户的IP地址,修正了NS部分,修正了一些错误,增加了常见问题。

配置步骤:
1. 前言
2. 软件列表
3. 安装BIND 9
4. 配置BIND 9
5. 测试BIND 9
6. 添加一个NS地址
7. 添加一个域名
8. 测试域名
9. 常见问题

一、 前言
本文假设你有一定的FreeBSD操作经验,懂得日常的FreeBSD操作,有良好的耐心,可以
把文档看完,可以处理突发的问题。
本文再假设你已经有了一个域名,并且已经指向所操作的服务器,服务器的/etc/rc.conf
已经正确的设置此域名。在本文里面,此域名为ns.naizhao.com,IP为219.132.1.1。
/etc/rc.conf如下所设置
hostname=”ns.naizhao.com” #机器的域名,请酌情修改
ifconfig_fxp0=”inet 219.132.1.1 netmask 255.255.255.0″ #此行可能有所不同,
请别照抄。fxp0为我机器上面的网卡。

二、 软件列表
本文所用到的软件可从以下地址获取。连接地址最后更新为2005/12/12

BIND 9.3.1
ftp://ftp.isc.org/isc/bind9/9.3.1/bind-9.3.1.tar.gz

三、 安装BIND 9
我们假设你已经把BIND 9使用fetch或者wget到/root/下,并且已经su为root。
# tar zxvf bind-9.3.1.tar.gz
# cd bind-9.3.1
# ./configure
# make
# make install
# make clean
到此,BIND 9已经安装上了。如果安装过程中出现什么问题,一般不会是你的人品有问题,
请分析错误信息,把缺少的包给安装上。

四、 配置BIND 9
先别急,看看你的BIND版本再说。
# named -v
如果你是FreeBSD 4,估计你看到的提示类似下面的
named 8.3.7-REL Sun Dec 12 04:15:36 CST 2004
如果你是FreeBSD 5,估计你不会看到上面的信息。然后我们再来输入
# /usr/local/sbin/named -v
这次,不管你是FreeBSD 4还是FreeBSD 5,都会看到下面的信息
BIND 9.3.1
所以在这里,我们统一使用/usr/local/sbin/named
废话少说,开始配置吧。
# cd /etc/namedb
# chmod +x make-localhost
# ./make-localhost
会在当前目录生成一个localhost.rev和localhost-v6.rev。后者是用于IPv6
生成rndc的key
# /usr/local/sbin/rndc-confgen >rndc.conf
打开rndc.conf,把
# Use with the following in named.conf, adjusting the allow list as needed:
……
# End of named.conf
之间的内容,去掉注释#,添加到named.conf中
编辑named.conf
# ee named.conf
找到
zone “.” {
type hint;
file “named.root”;
};

zone “0.0.127.IN-ADDR.ARPA” {
type master;
file “localhost.rev”;
};

// RFC 3152
zone “1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA” {
type master;
file “localhost-v6.rev”;
};

// RFC 1886 — deprecated
zone “1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.INT” {
type master;
file “localhost-v6.rev”;
};
把上面的内容全部用/**/注释
/*
zone “.” {
type hint;
……
file “localhost-v6.rev”;
};
*/
在named.conf文件的最后,把刚才rndc.conf里面的内容添加进去
key “rndc-key” {
algorithm hmac-md5;
secret “ILzfx8ONk2444ix9jnDfKA==”;
};

controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { “rndc-key”; };
};
(上面的内容只供参考)
接下来的,就是文章里面的重头戏了。

在上面添加的内容后面添加:
//include cnc acl
include “acl.conf”;

//view add by naizhao
view “view_cnc” {
match-clients { CNC; };
zone “.” {
type hint;
file “named.root”;
};

zone “0.0.127.IN-ADDR.ARPA” {
type master;
file “localhost.rev”;
};

include “master/cnc.def”;
};

view “view_any” {
match-clients { any; };
zone “.” {
type hint;
file “named.root”;
};

zone “0.0.127.IN-ADDR.ARPA” {
type master;
file “localhost.rev”;
};

include “master/telecom.def”;
};

添加完成后,保存。
# ee acl.conf
输入以下内容:
//cnc acl list by naizhao
acl “CNC” {
58.16.0.0/16;
58.17.0.0/17;
58.17.128.0/17;
58.18.0.0/16;
58.19.0.0/16;
58.20.0.0/16;
58.21.0.0/16;
58.22.0.0/15;
58.240.0.0/15;
58.242.0.0/15;
58.244.0.0/15;
58.246.0.0/15;
58.248.0.0/13;
60.0.0.0/13;
60.8.0.0/15;
60.10.0.0/16;
60.11.0.0/16;
60.12.0.0/16;
60.13.0.0/18;
60.13.128.0/17;
60.14.0.0/15;
60.16.0.0/13;
60.24.0.0/14;
60.30.0.0/16;
60.31.0.0/16;
60.208.0.0/13;
60.216.0.0/15;
60.218.0.0/15;
60.220.0.0/14;
61.48.0.0/13;
61.133.0.0/17;
61.134.96.0/19;
61.134.128.0/17;
61.135.0.0/16;
61.137.128.0/17;
61.138.0.0/17;
61.138.128.0/18;
61.139.128.0/18;
61.148.0.0/15;
61.156.0.0/16;
61.158.0.0/16;
61.159.0.0/18;
61.161.0.0/18;
61.161.128.0/17;
61.162.0.0/16;
61.163.0.0/16;
61.167.0.0/16;
61.168.0.0/16;
61.176.0.0/16;
61.179.0.0/16;
61.180.128.0/17;
61.181.0.0/16;
61.182.0.0/16;
61.189.0.0/17;
125.32.0.0/16;
125.40.0.0/13;
202.96.0.0/18;
202.96.64.0/21;
202.96.72.0/21;
202.97.128.0/18;
202.97.224.0/21;
202.97.240.0/20;
202.98.0.0/21;
202.98.8.0/21;
202.99.64.0/19;
202.99.96.0/21;
202.99.128.0/19;
202.99.160.0/21;
202.99.168.0/21;
202.99.176.0/20;
202.99.208.0/20;
202.99.224.0/21;
202.99.232.0/21;
202.99.240.0/20;
202.102.128.0/21;
202.102.224.0/21;
202.102.232.0/21;
202.106.0.0/16;
202.107.0.0/17;
202.108.0.0/16;
202.110.0.0/17;
202.111.128.0/18;
203.93.8.0/24;
203.93.192.0/18;
210.13.128.0/17;
210.14.160.0/19;
210.14.192.0/19;
210.15.32.0/19;
210.15.96.0/19;
210.15.128.0/18;
210.16.128.0/18;
210.21.0.0/16;
210.51.0.0/16;
210.52.128.0/17;
210.53.0.0/17;
210.53.128.0/17;
210.74.96.0/19;
210.74.128.0/19;
210.82.0.0/15;
211.152.0.0/13;
218.7.0.0/16;
218.8.0.0/14;
218.12.0.0/16;
218.21.128.0/17;
218.24.0.0/14;
218.28.0.0/15;
218.56.0.0/14;
218.60.0.0/15;
218.62.0.0/17;
218.67.128.0/17;
218.68.0.0/15;
218.104.0.0/14;
219.154.0.0/15;
219.156.0.0/15;
219.158.0.0/17;
219.158.128.0/17;
219.159.0.0/18;
220.252.0.0/16;
221.0.0.0/15;
221.2.0.0/16;
221.3.0.0/17;
221.3.128.0/17;
221.4.0.0/16;
221.5.0.0/17;
221.5.128.0/17;
221.6.0.0/16;
221.7.0.0/19;
221.7.32.0/19;
221.7.64.0/19;
221.7.96.0/19;
221.7.128.0/17;
221.8.0.0/15;
221.10.0.0/16;
221.11.0.0/17;
221.11.128.0/18;
221.11.192.0/19;
221.12.0.0/17;
221.12.128.0/18;
221.13.0.0/18;
221.13.64.0/19;
221.13.96.0/19;
221.13.128.0/17;
221.14.0.0/15;
221.192.0.0/15;
221.194.0.0/16;
221.195.0.0/16;
221.196.0.0/15;
221.198.0.0/16;
221.199.0.0/19;
221.199.32.0/20;
221.199.128.0/18;
221.199.192.0/20;
221.200.0.0/14;
221.204.0.0/15;
221.206.0.0/16;
221.207.0.0/18;
221.207.64.0/18;
221.207.128.0/17;
221.208.0.0/14;
221.212.0.0/16;
221.213.0.0/16;
221.216.0.0/13;
222.128.0.0/14;
222.132.0.0/14;
222.136.0.0/13;
222.160.0.0/15;
222.162.0.0/16;
222.163.0.0/19;
222.163.32.0/19;
222.163.64.0/18;
222.163.128.0/17;
219.235.56.194;
};
//cnc acl list by naizhao

# mkdir master
# touch master/cnc.def
# touch master/telecom.def
完成,接着就是测试

五、 测试BIND 9
# /usr/local/sbin/named -gc /etc/namedb/named.conf
正常的情况下你会看到下面的信息
12-Dec-2005 13:55:46.772 starting BIND 9.3.1 -gc /etc/namedb/named.conf
12-Dec-2005 13:55:46.816 loading configuration from ‘/etc/namedb/named.conf’
12-Dec-2005 13:55:46.824 no IPv6 interfaces found
12-Dec-2005 13:55:46.825 listening on IPv4 interface fxp0, 219.132.1.1#53
12-Dec-2005 13:55:46.825 listening on IPv4 interface lo0, 127.0.0.1#53
……
12-Dec-2005 13:55:46.866 running
只要有最后一行,那么你的配置就算是基本成功了。
按一下键盘的ctrl+c,先把BIND 9停掉。

六、 添加一个NS
平时大家修改域名信息的时候,都会发现有一个DNS信息的修改,里面会有一些类似ns7.hichina.com一样的东西。添加这个东西不难,在新网的后台就可以添加。添加的时候要注意,域名状态设置里面的域名必须不能在锁定状态。
登陆新网的后台->域名管理->注册本域名下的DNS->DNS名字:ns->IP地址219.132.1.1(按照自己要求修改IP地址)->确定->MyDNS功能->添加新的A记录->ns->IP地址219.132.1.1->提交。
对于一些收费的(如万网)或者不提供DNS服务器注册的管理后台,我们一样有办法去解决。首先按照上面的,先添加一个A记录,然后打开http://domain.cnic.ac.cn/domain/nameserver/createhost.jsp
按照上面的提示注册一下就行。
OK,等待DNS生效吧
这里要说明以下,如果按照上面的方法添加ns记录,在查询一个域名的时候,用户需要经过三步:
根域名服务器->新网/万网域名服务器->用户自己的域名服务器
所以我建议大家,尽量在国外注册域名,安全和稳定性比国内有保障,而且自由度高,像这样的服务都不需要收费的,并且查询只需要经过两步:
根域名服务器->用户自己的域名服务器
另外,对于.CN的域名,用户是需要经过四步的:
根域名服务器->DNS.cn->新网/万网域名服务器->用户自己的域名服务器
在国外注册域名来解析,也是有窍门的,用户可以自己对自己的域名来解析。比如:
wuhongsheng.com这个域名,我可以使用ns1.wuhongsheng.com/ns2.wuhongsheng.com
来对自己进行解析,在国内我发现还无法做到这点。
国外注册自己的NS记录,一般为Nameserver Registration,按照提示输入IP就行

七、 添加一个域名
# cd /etc/namedb/master
# mkdir cnc
# mkdir telecom
# ee cnc.def
添加
zone “wuhongsheng.com” {
type master;
file “master/cnc/wuhongsheng.com”;
};

# ee telecom.def
添加
zone “wuhongsheng.com” {
type master;
file “master/telecom/wuhongsheng.com”;
};
添加网通的解析,解析到的IP为202.111.1.1
#ee cnc/wuhongsheng.com
添加
$TTL 3600
$ORIGIN wuhongsheng.com.
@ IN SOA ns.naizhao.com. root.ns.naizhao.com.(
2005121013 ;Serial
3600 ; Refresh ( seconds )
900 ; Retry ( seconds )
68400 ; Expire ( seconds )
15 );Minimum TTL for Zone ( seconds )
;
@ IN NS ns.naizhao.com.
@ IN A 202.111.1.1
www IN A 202.111.1.1
;
;end
添加电信的解析,解析到的IP为219.132.1.2
#ee telecom/wuhongsheng.com
添加
$TTL 3600
$ORIGIN wuhongsheng.com.
@ IN SOA ns.naizhao.com. root.ns.naizhao.com.(
2005121013 ;Serial
3600 ; Refresh ( seconds )
900 ; Retry ( seconds )
68400 ; Expire ( seconds )
15 );Minimum TTL for Zone ( seconds )
;
@ IN NS ns.naizhao.com.
@ IN A 219.132.1.2
www IN A 219.132.1.2
;
;end
添加一个脚本,用于在系统启动的时候自动把DNS服务器启起来
# ee /usr/local/etc/rc.d/named.sh
添加内容
/usr/local/sbin/named -gc /etc/namedb/named.conf &
# chmod 777 /usr/local/etc/rc.d/named.sh
把服务器启起来
# /usr/local/etc/rc.d/named.sh
OK,到此你的DNS服务器就算是跑起来了。试一下分别用网通和电信的线路ping一下吧,嘿嘿。

八、 测试域名
除了用简单的ping来测试域名外,你还可以使用nslookup来测试域名
# nslookup
>server ns.naizhao.com
>set q=a
>wuhongsheng.com
当然,unix系统下面还可以使用dig来进行高级查询
dig @ns.naizhao.com a wuhongsheng.com
原创文章,转载请注明来自http://wuhongsheng.com

九、常见问题
Q:为什么我测试的时候,得到的IP不是网通的?
A:首先确认你的配置是否对了。另外一个最重要的问题,你本地的DNS请求不是直接向你的DNS服务器发送,而是你本机先向系统设置的DNS服务器发送请求,然后由DNS服务器再向你自己的DNS服务器发送请求。所以,如果你本机设置了电信的DNS服务器地址,自然就解析不出网通的记录了。

97 thoughts on “架构根据电信、网通用户自动解析不同IP的DNS服务器”

  1. First of all I would like to say terrific blog! I had a quick question which I’d
    like to ask if you do not mind. I was curious to know how you center
    yourself and clear your head prior to writing.
    I have had trouble clearing my mind in getting my ideas out there.
    I truly do take pleasure in writing but it just seems like the first 10 to 15 minutes tend to be
    wasted just trying to figure out how to begin. Any recommendations or hints?
    Many thanks!

  2. Do you mind if I quote a couple of your posts
    as long as I provide credit and sources back to
    your blog? My blog is in the very same niche as yours and
    my visitors would truly benefit from a lot of the information you present here.
    Please let me know if this alright with you.
    Cheers!

  3. Does your website have a contact page? I’m having a tough time locating it but, I’d like
    to send you an e-mail. I’ve got some creative
    ideas for your blog you might be interested in hearing.
    Either way, great blog and I look forward to seeing it
    grow over time.

  4. Admiring the commitment you put into your blog and in depth information you provide.
    It’s awesome to come across a blog every once in a while that isn’t the
    same outdated rehashed information. Wonderful read!
    I’ve saved your site and I’m including your RSS feeds
    to my Google account.

  5. Hello! I know this is kinda off topic but I’d figured I’d ask.
    Would you be interested in exchanging links or maybe guest authoring a blog post
    or vice-versa? My blog discusses a lot of the same subjects as yours and I think we could greatly benefit from each other.
    If you happen to be interested feel free to send me an e-mail.
    I look forward to hearing from you! Great blog by the way!

  6. Pretty section of content. I just stumbled upon your site and in accession capital to assert that I acquire actually
    enjoyed account your blog posts. Anyway I’ll be subscribing to your feeds and even I achievement you access consistently
    rapidly.

  7. Hi there I am so happy I found your blog page, I really
    found you by mistake, while I was searching on Yahoo for something else, Anyways I am here now and would just like to say
    many thanks for a marvelous post and a all round entertaining
    blog (I also love the theme/design), I don’t have time to read it all
    at the minute but I have book-marked it and also included your RSS feeds,
    so when I have time I will be back to read much more, Please
    do keep up the great work.

  8. Hi there, I discovered your web site by the use of Google while
    looking for a related matter, your site came up, it looks great.
    I have bookmarked it in my google bookmarks.
    Hello there, just become alert to your blog thru Google, and found that it is truly informative.
    I am gonna watch out for brussels. I’ll be grateful should you
    continue this in future. Many other folks will probably be benefited from your writing.
    Cheers!

  9. You actually make it appear so easy with your presentation but
    I find this topic to be actually something that I think I would by no
    means understand. It sort of feels too complicated and
    extremely broad for me. I am looking forward to your next submit,
    I will attempt to get the hold of it!

  10. Hello there I am so excited I found your blog page, I really found you by mistake, while I was looking on Google for something
    else, Anyways I am here now and would just like to say thank you for a marvelous post and a
    all round exciting blog (I also love the theme/design), I don’t
    have time to read it all at the moment but I have book-marked it and also added
    your RSS feeds, so when I have time I will be back to read much more, Please do keep up the great work.

  11. Hey I know this is off topic but I was wondering if
    you knew of any widgets I could add to my blog that automatically tweet my
    newest twitter updates. I’ve been looking for a plug-in like
    this for quite some time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy
    reading your blog and I look forward to your new updates.

  12. hello there and thank you for your information – I’ve
    certainly picked up anything new from right here. I did however expertise a few technical issues using this website,
    as I experienced to reload the site many times previous to I could get it to load correctly.

    I had been wondering if your hosting is OK? Not that I’m complaining, but slow loading instances times will very frequently
    affect your placement in google and could damage your high
    quality score if advertising and marketing with Adwords.
    Anyway I am adding this RSS to my e-mail and could look out for a lot more
    of your respective intriguing content. Ensure that you update this again soon.

  13. Good day I am so happy I found your web site, I really found you by error, while I was searching on Yahoo for something else, Anyways I am here now and would just like to say many thanks for a fantastic post and a all round enjoyable blog (I also love the theme/design), I
    don’t have time to read through it all at the moment but I have book-marked
    it and also added in your RSS feeds, so when I have time I will be back to read a lot more, Please do
    keep up the superb job.

  14. Pingback: Type fences
  15. Excellent goods from you, man. I have take note your stuff
    prior to and you’re simply too excellent. I actually like
    what you’ve received right here, certainly like what you are stating and the best way wherein you
    say it. You are making it enjoyable and you still take care of to keep it smart.
    I can not wait to read much more from you. This is really a great website.

  16. Magnificent goods from you, man. I’ve take into account your stuff prior to and you are simply too
    great. I really like what you have obtained here,
    certainly like what you are saying and the best way by which you say it.
    You make it enjoyable and you still take care of to stay it wise.
    I can not wait to learn much more from you. This is actually a wonderful
    site.

  17. Howdy! This blog post could not be written much better!
    Looking at this post reminds me of my previous roommate!

    He constantly kept preaching about this. I am going to
    send this article to him. Pretty sure he’s going to have a
    good read. Thanks for sharing!

  18. Pingback: My Homepage
  19. cant miss deals on womens orthofeet whitney white leather alo yoga velvet puffer rosewood jacket unionbay mens cordova belted cargo short messenger 34 grain quiksilver mens everyday kaimana 21 boardshort swim trunk board shorts forever 21 denim overall shorts memento mori knee sleeves rogue american women 39 s relaxed fit 5 quot stretch denim utility shorts rinsed indigo ssnb womens sexy activewear stretch pants yoga leggings
    home men t shirts breaking benjamin dark before dawn tour t shirt black http://www.parslawyersgroup.com/saintonge_sweetvalley/home-men-t-shirts-breaking-benjamin-dark-before-dawn-tour-t-shirt-black

  20. suchergebnis auf f眉r puma unterw盲sche herren backpacking rucksack test top beratung nike schuhe billig aus amerika damen baumwolle umstandsmode shirt lange umstandsmode 盲rmel only blazer g眉nstiger kaufen damen blazer nachtblau wei脽 umh盲ngetasche louis vuitton herren nike herren schuhe g眉nstig damen 3 4 hosen 2018 b.c. best connections by heine hose
    tamaris pumps mit plateausohle in schwarz synthetik http://www.habiganjprotidin.com/lakeville_rougemont/tamaris-pumps-mit-plateausohle-in-schwarz-synthetik

Leave a Reply

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

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image