手机版
你好,游客 登录 注册
背景:
阅读新闻

缓存DNS服务器和主DNS服务器的快速搭建详解

[日期:2013-04-18] 来源:Linux社区  作者:ywhwzhang [字体:大 中 小]

上一节中我们说了关于如何构建缓存DNS和主DNS的快速搭建,这里算是一个续篇,为了说明如何构建主从DNS服务器以实现DNS的冗余负载均衡。所以在这里的一切配置都是基于上一章的内容,如有不解请参考上一章(http://www.linuxidc.com/Linux/2013-04/83018.htm),对您造成的不变请谅解。

一、设定配置内容

在上一章的时候我们假设已经在网上注册了linuxidc.com域名,得到的IP网络是172.16.12.0/24

主DNS服务器的配置是:

ns服务器是:172.16.12.1

www服务器:172.16.12.1,另外一个地址:172.16.12.3

mail服务器:172.16.12.5

从DNS的配置大致类似(从服务器IP为172.16.12.2)

二、准备工作:

因为在上一节中已经讲过,这里就不再说明了。

三、命令解析

DNS服务是我们为公司或者其他机构提供的域名解析服务,那么这里就一定有一个范围的界定,不仅仅是为了安全,也能够让服务的资源更大限度的为客户服务,而不是被一些人恶意的攻击。

上一篇中我们提到了dig命令,dig命令不仅仅可以用来查询测试我们的DNS服务是否能够正常使用,还可以在查询传送我们主服务器的全部内容,和增量内容。所以这里我们就必须要对能够查询的对象做进一步的限定,这样才能够尽量的保证我们服务器的安全。我们可以使用recursion命令来觉得开启或者关闭递归功能,默认递归功能是开启状态;使用allow-recursion { NET;};来为某个网段提供递归服务;使用allow-query确定允许查询的用户(不过这样一来构建的DNS服务器就不能够面对公共服务了);使用allow-transfer定义允许传送数据的用,这里我们一般都只设定从服务器才能够传送信息。

[root@linuxidc named]# dig -t axfr linuxidc.com @172.16.12.1 我们允许完全查询DNS服务器的所有信息

  1. [root@linuxidc named]# dig -t axfr linuxidc.com @172.16.12.1
  2. ; <<>> DiG 9.7.0-P2-RedHat-9.7.0-6.P2.el5_7.4 <<>> -t axfr linuxidc.com @172.16.12.1
  3. ;; global options: +cmd
  4. linuxidc.com. 3600 IN SOA ns1.linuxidc.com. admin.linuxidc.com. 3360030017280021600
  5. linuxidc.com. 3600 IN NS ns1.linuxidc.com.
  6. linuxidc.com. 3600 IN MX 10 mail.linuxidc.com.
  7. *.linuxidc.com. 3600 IN A 172.16.12.1
  8. ftp.linuxidc.com. 3600 IN CNAME www.linuxidc.com.
  9. mail.linuxidc.com. 3600 IN A 172.16.12.2
  10. ns1.linuxidc.com. 3600 IN A 172.16.12.1
  11. www.linuxidc.com. 3600 IN A 172.16.12.1
  12. www.linuxidc.com. 3600 IN A 172.16.12.3
  13. linuxidc.com. 3600 IN SOA ns1.linuxidc.com. admin.linuxidc.com. 3360030017280021600
  14. ;; Query time: 2 msec
  15. ;; SERVER: 172.16.12.1#53(172.16.12.1)
  16. ;; WHEN: Wed Apr 316:55:162013
  17. ;; XFR size: 10 records (messages 1, bytes 249)

 

 

[root@linuxidc named]# dig -t IXFR=3 linuxidc.com @172.16.12.1 修改主DNS服务器配置之后,我们增量查询一下

  1. [root@linuxidc named]# dig -t IXFR=3 linuxidc.com @172.16.12.1
  2. ; <<>> DiG 9.7.0-P2-RedHat-9.7.0-6.P2.el5_7.4 <<>> -t IXFR=3 linuxidc.com @172.16.12.1
  3. ;; global options: +cmd
  4. linuxidc.com. 3600 IN SOA ns1.linuxidc.com. admin.linuxidc.com. 3360030017280021600
  5. ;; Query time: 4 msec
  6. ;; SERVER: 172.16.12.1#53(172.16.12.1)
  7. ;; WHEN: Wed Apr 316:57:032013
  8. ;; XFR size: 1 records (messages 1, bytes 74)

 

 

[root@linuxidc ~]# dig -t axfr linuxidc.com @172.16.12.1 我们使用允许以外的主机查询

  1. [root@linuxidc ~]# dig -t axfr linuxidc.com @172.16.12.1
  2. ; <<>> DiG 9.7.0-P2-RedHat-9.7.0-6.P2.el5_7.4 <<>> -t axfr linuxidc.com @172.16.12.1
  3. ;; global options: +cmd
  4. ; Transfer failed.

 

 

四、配置从DNS服务器

1、首先需要安装好bind97.i386、bind97-libs.i386、bind97-utils.i386这三个软件包。构建好我们的DNS环境平台。然后临时性关闭SELinux服务,防止SELinux对我们的配置造成不必要的影响。

2、修改添加主服务器的主配置文件:vim /etc/named.conf

  1. [root@linuxidc named]# vim /etc/named.conf
  2. options {
  3. directory "/var/named";
  4. };
  5. zone "." IN {
  6. type hint;
  7. file "named.ca";
  8. };
  9. zone "localhost" IN {
  10. type master;
  11. file "named.localhost";
  12. };
  13. zone "0.0.127.in-addr.arpa" IN {
  14. type master;
  15. file "named.loopback";
  16. };
  17. zone "linuxidc.com" IN {
  18. type master; #指定主从类型
  19. file "linuxidc.com.zone"; #指定区域数据文件
  20. allow-transfer { 172.16.12.2; }; #只允许172.16.12.2传输信息
  21. };
  22. zone "12.16.172.in-addr.arpa" IN {
  23. type master; #指定主从类型
  24. file "172.16.12.zone"; #指定区域数据文件
  25. allow-transfer { 172.16.12.2; }; #只允许172.16.12.2传输信息
  26. };

 

 

3、配置从服务器的主配置文件(这里就不需要为从服务器添加区域数据文件了)

vim /etc/named.conf

  1. [root@linuxidc named]# vim /etc/named.conf
  2. options {
  3. directory "/var/named";
  4. };
  5. zone "." IN {
  6. type hint;
  7. file "named.ca";
  8. };
  9. zone "localhost" IN {
  10. type master;
  11. file "named.localhost";
  12. };
  13. zone "0.0.127.in-addr.arpa" IN {
  14. type master;
  15. file "named.loopback";
  16. };
  17. zone "linuxidc.com" IN {
  18. type slave; #指定主从类型
  19. file "slaves/linuxidc.com.zone"; #指定区域数据文件
  20. masters { 172.16.12.1; }; #指定主服务地址
  21. allow-transfer { none; }; #禁止其他主机传送数据
  22. };
  23. zone "12.16.172.in-addr.arpa" IN {
  24. type slave; #指定主从类型
  25. file "slaves/172.16.12.zone"; #指定区域数据文件
  26. masters { 172.16.12.1; }; #指定主服务地址
  27. allow-transfer { none; }; #禁止其他主机传送数据
  28. };

 

 

4、重启服务,测试主从服务器能否正常使用和传送数据

tail /var/log/messages

  1. [root@linuxidc ~]# tail /var/log/messages
  2. Apr 317:07:13 localhost named[6146]: client 172.16.12.1#52450: zone transfer 'linuxidc.com/AXFR/IN' denied
  3. Apr 317:18:35 localhost named[6146]: client 172.16.12.2#41948: transfer of '12.16.172.in-addr.arpa/IN': AXFR started
  4. Apr 317:18:35 localhost named[6146]: client 172.16.12.2#41948: transfer of '12.16.172.in-addr.arpa/IN': AXFR ended
  5. Apr 317:18:36 localhost named[6146]: client 172.16.12.2#56157: transfer of 'linuxidc.com/IN': AXFR started
  6. Apr 317:18:36 localhost named[6146]: client 172.16.12.2#56157: transfer of 'linuxidc.com/IN': AXFR ended

 

 

查看同步结果:(注意此时的版本号为1)

  1. [root@linuxidc named]# cat ./slaves/linuxidc.com.zone
  2. $ORIGIN .
  3. $TTL 3600 ; 1 hour
  4. linuxidc.com IN SOA ns1.linuxidc.com. admin.linuxidc.com. (
  5. 1 ; serial
  6. 3600 ; refresh (1 hour)
  7. 300 ; retry (5 minutes)
  8. 172800 ; expire (2 days)
  9. 21600 ; minimum (6 hours)
  10. )
  11. NS ns1.linuxidc.com.
  12. MX 10 mail.linuxidc.com.
  13. $ORIGIN linuxidc.com.
  14. ftp CNAME www
  15. mail A 172.16.12.5
  16. ns1 A 172.16.12.1
  17. www A 172.16.12.1
  18. A 172.16.12.3

接下来我们修改主服务器的解析域条目,然后查看一下主从服务器能否自动获得更新:

主DNS服务器日志���

  1. [root@linuxidc named]# tail /var/log/messages
  2. Apr 316:16:14 localhost last message repeated 4 times
  3. Apr 316:19:08 localhost named[6146]: client 172.16.12.2#51841: transfer of 'linuxidc.com/IN': AXFR-style IXFR started
  4. Apr 316:19:08 localhost named[6146]: client 172.16.12.2#51841: transfer of 'linuxidc.com/IN': AXFR-style IXFR ended

从DNS服务器日志:(注意,在日志中已经显示了我们修改后的版本号)

  1. [root@linuxidc named]# tail /var/log/messages
  2. Apr 316:16:14 localhost last message repeated 4 times
  3. Apr 316:19:08 localhost named[6801]: zone linuxidc.com/IN: Transfer started.
  4. Apr 316:19:08 localhost named[6801]: transfer of 'linuxidc.com/IN'from172.16.12.1#53: connected using 172.16.12.2#51841
  5. Apr 316:19:08 localhost named[6801]: zone linuxidc.com/IN: transferred serial 2
  6. Apr 316:19:08 localhost named[6801]: transfer of 'linuxidc.com/IN'from172.16.12.1#53: Transfer completed: 1 messages, 10 records, 249 bytes, 0.030 secs (8300 bytes/sec)

最后我们查看一下从服务器是否真正接收到了数据(此时的从服务的数据版本号已经转变为2)

  1. [root@linuxidc named]# cat ./slaves/linuxidc.com.zone
  2. $ORIGIN .
  3. $TTL 3600 ; 1 hour
  4. linuxidc.com IN SOA ns1.linuxidc.com. admin.linuxidc.com. (
  5. 2 ; serial
  6. 3600 ; refresh (1 hour)
  7. 300 ; retry (5 minutes)
  8. 172800 ; expire (2 days)
  9. 21600 ; minimum (6 hours)
  10. )
  11. NS ns1.linuxidc.com.
  12. MX 10 mail.linuxidc.com.
  13. $ORIGIN linuxidc.com.
  14. * A 172.16.12.1
  15. ftp CNAME www
  16. mail A 172.16.12.5
  17. ns1 A 172.16.12.1
  18. www A 172.16.12.1
  19. A 172.16.12.3

五、下期介绍:

在DNS服务器的使用过程中我们会遇到各种的问题,很多的时候不单单一台服务器就能够搞定的,这个时候就需要我们为自己的服务器添加子域,为子域授权。

当我们的DNS服务器在为众多的域提供服务的时候,上面的那些简单配置就会显得越来越繁琐,那我们ACL就是能够帮助我们在越来越繁琐的工作中找到一个捷径的办法。

linux
相关资讯       DNS缓存服务器  DNS服务器搭建 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款