【子域授权】
【实验说明】:新增一台服务器ip为192.168.0.112,配置成为test.com子域(a.test.com)的主DNS
【实验验证】:子域可以实现自我管理,通过父域DNS可以查询解析子域,但子域无法查询解析父域。
【实验步骤】:
1、进行正向子域授权,只需要在父域的区域解析库中添加“胶水记录”;
[[email protected] ~]# vim /var/named/test.com.zone $TTL 86400 @ IN SOA ns.test.com. admin.test.com. ( 2015052613 2H 10M 7D 1D ) IN NS ns.test.com. a IN NS ns.a.test.com. #添加子域的NS记录; IN MX 10 mail.test.com. ns IN A 192.168.0.111 ns.a IN A 192.168.0.112 #添加子域的A记录; www IN A 192.168.0.113 mail IN A 192.168.0.114 web IN A 192.168.0.115 pop3 IN CNAME mail.test.com.
2、配置子域服务器的配置文件与数据库解析文件;
[[email protected] ~]# vim /etc/named.rfc1912.zones #在子域服务器上配置区域; zone "a.test.com" IN { type master; file "a.test.com.zone"; }; zone "0.168.192.in-addr.arpa" IN { type master; file "192.168.0.zone"; }; [[email protected] ~]# vim /var/named/a.test.com.zone #配置正向解析库文件; $TTL 86400; a.test.com. IN SOA ns.a.test.com. admin.a.test.com ( 2015052800 1H 5M 7D 3H ) a.test.com. IN NS ns.a.test.com. mail IN MX 10 mail ns IN A 192.168.0.112 mail IN A 192.168.0.118 www IN A 192.168.0.119 [[email protected] ~]# vim /var/named/192.168.0.zone #配置反向解析库文件; $TTL 86400 @ IN SOA ns.a.test.com. admin.a.test.com ( 2015052800 1H 5M 7D 8H ) IN NS ns.a.test.com. 112 IN PTR ns.a.test.com. 118 IN PTR mail.a.test.com. 119 IN PTR
3、通过以上两部一个简单的子域就创建好了,现在测试下;
[[email protected] ~]# dig -t A www.a.test.com @192.168.0.111 #在父域上测序解析子域主机; ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> -t A www.a.test.com @192.168.0.111 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27976 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 #看到没有flags里面没有aa,验证通过父域来解析得到的不是权威应答; ;; QUESTION SECTION: ;www.a.test.com. IN A ;; ANSWER SECTION: #解析成功! ;; AUTHORITY SECTION: a.test.com. 86400 IN NS ns.a.test.com. ;; ADDITIONAL SECTION: ns.a.test.com. 86400 IN A 192.168.0.112 ;; Query time: 39 msec ;; SERVER: 192.168.0.111#53(192.168.0.111) ;; WHEN: Fri May 29 19:51:29 2015 ;; MSG SIZE rcvd: 81 [[email protected] ~]# dig -t A www.a.test.com @192.168.0.112 #子域自己解析测试; ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> -t A www.a.test.com @192.168.0.112 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13045 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 #flags里面有aa,验证其自己解析时得到的是权威响应; ;; QUESTION SECTION: ;www.a.test.com. IN A ;; ANSWER SECTION: #解析成功! ;; AUTHORITY SECTION: a.test.com. 86400 IN NS ns.a.test.com. ;; ADDITIONAL SECTION: ns.a.test.com. 86400 IN A 192.168.0.112 ;; Query time: 1 msec ;; SERVER: 192.168.0.112#53(192.168.0.112) ;; WHEN: Fri May 29 19:49:40 2015 ;; MSG SIZE rcvd: 81 [[email protected] ~]# dig -t A www.test.com @192.168.0.112 #通过子域DNS来解析父域服务器; ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> -t A www.test.com @192.168.0.112 ;; global options: +cmd ;; connection timed out; no servers could be reached #无法解析到,验证了子域无法解析父域;
【转发】
通过上面的实验我们可以发现,子域是不知道父域是在什么地方的,当然也就不能解析父域,那有什么办法可以解决这个问题呢?当然有,而且很简单,我们只需要配置子域转发就可以了。
[[email protected] ~]# vim /etc/named.conf #编辑子域的配置文件; options { forward first ; #设置为转发且模式为first,还可以把模式设置为only; #only为递归请求,如转发服务器返回目标无法解析,则接受这个结果; #first:首先发送递归请求,如果转发服务器返回目标无法解析,则本机再次自行去查询请求; forwarders { 192.168.0.111; };#转发至何处,具体值可以看随后补充说明; }; [[email protected] ~]# service named restart Stopping named: . [ OK ] Starting named: [ OK ] [[email protected] ~]# dig -t A www.test.com @192.168.0.112 #测试通过子域查询父域; ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> -t A www.test.com @192.168.0.112 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18252 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 13, ADDITIONAL: 0 ;; QUESTION SECTION: ;www.test.com. IN A ;; ANSWER SECTION: ;; Query time: 1198 msec ;; SERVER: 192.168.0.112#53(192.168.0.112) ;; WHEN: Fri May 29 20:41:09 2015 ;; MSG SIZE rcvd: 257 #经过这样简单的配置,可以查询解析父域,但同时引入了另外一个问题,我们修改的是全局配置,导致 #所有通过子域的其他域查询都会转发到父域去,本不该是父域负责的解析父域都要去做,这肯定是不合 #理的,为此我们需要单独指定只有对父域的查询才转发到父域。 [[email protected] ~]# vim /etc/named.rfc1912.zones #只需要在配置文件中指定针对父域进行转发; zone "test.com" IN { type forward; forward first; forwarders { 192.168.0.111; } ; };
补充说明:
访问控制:
allow-transfer {}; 定义允许传输的白名单;
allow-query {}; 定义允许查询的白名单;
allow-update {}; 定义允许更新的白名单;
allow-recursion {}; 定义允许递归的白名单;
recursion yes; 所有主机都可以递归;
bind的访问控制列表(ACL):
内置的ACL:
none(都不允许), any(所有都允许), local(本机), localnet(本机所在网络)
自定义acl:
acl ACL_NAME {
ip;
ip;
network;
};
例: acl localnetwork {
172.16.0.0/16;
192.168.0.0/24;
};
allow-recursion { localnetwork; };
【视图】
根据客户端来源的不同,将同一个名称解析至不同的值,也可以叫做智能解析,我们可以把来自电信的解析到电信机房的服务器,把来自联通的请求解析到联通机房的服务器。下面我们假设我们电信机房的WEB服务器ip为192.168.0.113,联通机房的WEB服务器地址为:172.16.0.10
第一步,修改配置文件定义ACL与view;
[[email protected] ~]# vim /etc/named.conf acl unicom { #定义联通的ACL,名为unicom; 192.168.0.111; }; view "unicom" { #定义联通视图,名为unicom match-clients { unicom; }; #匹配该选项的,使用如下区域进行解析; zone "test.com" { type master; file "unicom.test.com.zone"; }; }; view "telnet" { match-clients { any; }; #按顺序执行,只要没有匹配到unicom的都匹配该选项的,使用如下区 域进行解析; zone "test.com" { type master; file "test.com.zone"; }; };
第二步,创建区域库解析文件unicom.test.com与test.com,此处不在做说明演示;
第三步,测试结果;
[[email protected] ~]# dig -t A www.test.com @192.168.0.111 #在Ip为192.168.0.111的主机上进行查询; ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> -t A www.test.com @192.168.0.111 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39197 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;www.test.com. IN A ;; ANSWER SECTION: #、解析到了联通机房的服务器; ;; AUTHORITY SECTION: test.com. 86400 IN NS ns.test.com. ;; ADDITIONAL SECTION: ns.test.com. 86400 IN A 192.168.0.111 ;; Query time: 1 msec ;; SERVER: 192.168.0.111#53(192.168.0.111) ;; WHEN: Fri May 29 21:30:01 2015 ;; MSG SIZE rcvd: 79 [[email protected] ~]# dig -t A www.test.com @192.168.0.111 #在ip为192.168.0.112的主机上进行查询; ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> -t A www.test.com @192.168.0.111 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7626 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;www.test.com. IN A ;; ANSWER SECTION: #解析到了电信机房的服务器; ;; AUTHORITY SECTION: test.com. 86400 IN NS ns.test.com. ;; ADDITIONAL SECTION: ns.test.com. 86400 IN A 192.168.0.111 ;; Query time: 4 msec
好了,就实验至此,希望各位大神多多拍砖!谢谢!