在某些场景下,我们可能需要针对同一个网站,不同地域或不同类别的用户得到不同的解析结果,这时候,就需要通过借助DNS的访问控制功能来实现。下面就让我们一起来一探究竟。
定义ACL
- 配置主配置文件。由于acl需要配合视图(view)使用,而一旦启用视图,就必须将所有的zone放在视图内,因此需要删除或注释主配置文件里的根域信息(当然,你也可以直接在主配置文件中定义视图)。
[root@centos7 named]# vim /etc/named.conf
acl xm{ #创建一个名为xm的acl。需要注意的是,acl必须先定义后使用,且一般定义于Options前
192.168.1.100;
};
acl fz{
192.168.1.50;
};
//zone "." IN { #注释根域相关信息
// type hint;
// file "named.ca";
//};
lsl
定义View
- 修改辅助配置文件
[root@centos7 named]# cp /etc/named.rfc1912.zones /etc/named.rfc1912.zones.bak #为更好地体现演示效果,笔者这里备份辅助配置文件,然后清空并重写辅助配置文件
[root@centos7 named]# >/etc/named.rfc1912.zones
[root@centos7 named]# vim /etc/named.rfc1912.zones
view xm{ #创建一个名为"xm"的视图
match-clients { xm;}; #匹配允许访问的客户端
zone "xm.zhimajihua.cn" IN { #这里对xm域进行解析,但和下面的2个视图使用不同的区域解析库文件
type master;
file "xm.zhimajihua.cn.zone"; #注意文件名的不同
allow-update { none; };
};
zone "." IN { #定义根域
type hint;
file "named.ca";
};
};
view fz{
match-clients { fz;};
zone "xm.zhimajihua.cn" IN {
type master;
file "xm.zhimajihua.cn.zone.with.fz"; #注意文件名的不同
allow-update { none; };
};
zone "." IN {
type hint;
file "named.ca";
};
};
view other{
match-clients { any; }; #any为named服务的内置acl变量,意为任意主机。客户端请求到达时,将自上而下检查每个view所服务的客户端列表。因此,一般将该any置于最后1个视图,用于匹配默认解析
zone "xm.zhimajihua.cn" IN {
type master;
file "xm.zhimajihua.cn.zone.with.other"; #注意文件名的不同
};
zone "." IN {
type hint;
file "named.ca";
};
};
[root@centos7 named]# named-checkconf #配置文件语法检查
routeros
创建区域解析库文件
- 创建匹配各个视图的区域解析库文件
[root@centos7 named]# cp -p xm.zhimajihua.cn.zone xm.zhimajihua.cn.zone.with.fz #对应名为fz的视图
[root@centos7 named]# cp -p xm.zhimajihua.cn.zone xm.zhimajihua.cn.zone.with.other #对应名为other的视图
[root@centos7 named]# ll
total 40
drwxrwx--- 2 named named 4096 Sep 27 03:32 data
drwxrwx--- 2 named named 4096 Sep 27 05:33 dynamic
-rw-r----- 1 root named 2076 Jan 28 2013 named.ca
-rw-r----- 1 root named 152 Dec 15 2009 named.empty
-rw-r----- 1 root named 152 Jun 21 2007 named.localhost
-rw-r----- 1 root named 168 Dec 15 2009 named.loopback
drwxrwx--- 2 named named 4096 Nov 11 2016 slaves
-rw-r----- 1 root named 201 Sep 27 03:39 xm.zhimajihua.cn.zone
-rw-r----- 1 root named 201 Sep 27 03:39 xm.zhimajihua.cn.zone.with.fz
-rw-r----- 1 root named 201 Sep 27 03:39 xm.zhimajihua.cn.zone.with.other
[root@centos7 named]# vim xm.zhimajihua.cn.zone #编辑对应名为xm的视图的区域解析库文件
siming A 192.168.1.99 #添加一条A记录
[root@centos7 named]# vim xm.zhimajihua.cn.zone.with.fz #编辑对应名为fz的视图的区域解析库文件
siming A 192.168.1.88
[root@centos7 named]# vim xm.zhimajihua.cn.zone.with.other #编辑对应名为other的视图的区域解析库文件
siming A 192.168.1.66
[root@centos7 named]# rndc reload
server reload successful
[root@centos7 named]# named-checkzone 'xm.zhimajihua.cn.zone' xm.zhimajihua.cn.zone
zone xm.zhimajihua.cn.zone/IN: loaded serial 20170927
OK
[root@centos7 named]# named-checkzone 'xm.zhimajihua.cn.zone' xm.zhimajihua.cn.zone.with.fz
zone xm.zhimajihua.cn.zone/IN: loaded serial 20170927
OK
[root@centos7 named]# named-checkzone 'xm.zhimajihua.cn.zone' xm.zhimajihua.cn.zone.with.other
zone xm.zhimajihua.cn.zone/IN: loaded serial 20170927
OK
tap
客户端测试
- 在客户端192.168.25.140上测试
[root@mini7 ~]# dig siming.xm.zhimajihua.cn @192.168.1.21
; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7 <<>> siming.xm.zhimajihua.cn @192.168.1.21
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26404
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;siming.xm.zhimajihua.cn. IN A
;; ANSWER SECTION:
siming.xm.zhimajihua.cn. 86400 IN A 192.168.1.99
;; AUTHORITY SECTION:
xm.zhimajihua.cn. 86400 IN NS ns1.xm.zhimajihua.cn.
;; ADDITIONAL SECTION:
ns1.xm.zhimajihua.cn. 86400 IN A 192.168.1.21
;; Query time: 0 msec
;; SERVER: 192.168.1.21#53(192.168.1.21)
;; WHEN: Wed Sep 27 14:32:26 CST 2017
;; MSG SIZE rcvd: 102
css - 在客户端192.168.25.141上测试
[root@mini6~]# dig siming.xm.zhimajihua.cn @192.168.1.21
; <<>> DiG 9.9.4-RedHat-9.9.4-37.el7 <<>> siming.xm.zhimajihua.cn @192.168.1.21
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7538
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;siming.xm.zhimajihua.cn. IN A
;; ANSWER SECTION:
siming.xm.zhimajihua.cn. 86400 IN A 192.168.1.88
;; AUTHORITY SECTION:
xm.zhimajihua.cn. 86400 IN NS ns1.xm.zhimajihua.cn.
;; ADDITIONAL SECTION:
ns1.xm.zhimajihua.cn. 86400 IN A 192.168.1.21
;; Query time: 0 msec
;; SERVER: 192.168.1.21#53(192.168.1.21)
;; WHEN: Wed Sep 27 14:33:10 GMT 2017
;; MSG SIZE rcvd: 102
css - 在其它客户端上测试
[root@wang ~]# dig siming.xm.zhimajihua.cn @192.168.1.21
; <<>> DiG 9.9.9-P1 <<>> siming.xm.zhimajihua.cn @192.168.1.21
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6755
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;siming.xm.zhimajihua.cn. IN A
;; ANSWER SECTION:
siming.xm.zhimajihua.cn. 86400 IN A 192.168.1.66
;; AUTHORITY SECTION:
xm.zhimajihua.cn. 86400 IN NS ns1.xm.zhimajihua.cn.
;; ADDITIONAL SECTION:
ns1.xm.zhimajihua.cn. 86400 IN A 192.168.1.21
;; Query time: 0 msec
;; SERVER: 192.168.1.21#53(192.168.1.21)
;; WHEN: Wed Sep 27 14:33:55 DST 2017
;; MSG SIZE rcvd: 102
网友评论