09-02 搭建并实现智能DNS
1.环境
名称 | IP | DNS |
---|---|---|
node1 DNS服务器 | 192.168.100.11 / 10.0.0.11 | - |
node2 北京客户端 | 192.168.100.13 | 192.168.100.11 |
node3 上海客户端 | 10.0.0.13 | 10.0.0.11 |
node4 Web服务器1 | 192.168.100.15 | - |
node5 Web服务器2 | 10.0.0.15 | - |
如下图所示:
2.DNS服务器配置
2.1 修改配置
[root@node1 ~]# yum install -y bind
[root@node1 ~]# vim /etc/named.conf
# acl访问控制列表(地址集合表)写上面
acl beijing{
192.168.100.0/24;
};
acl shanghai{
10.0.0.0/24;
};
acl other{
any;
};
# 注释掉
#listen-on port 53 { 127.0.0.1; };
#allow-query { localhost; };
# 尾部写view
view beijingview {
match-clients { beijing;};
include "/etc/named.rfc1912.zones.bj";
};
view shanghaiview {
match-clients { shanghai;};
include "/etc/named.rfc1912.zones.sh";
};
view otherview {
match-clients { other;};
include "/etc/named.rfc1912.zones.other";
};
#删除原有include "/etc/named.rfc1912.zones 保留include "/etc/named.root.key";
2.2 区域配置文件
[root@node1 ~]# vim /etc/named.rfc1912.zones.bj
zone "." IN {
type hint;
file "named.ca";
};
zone "feifa.cn" {
type master;
file "feifa.cn.zone.bj";
};
[root@node1 ~]# vim /etc/named.rfc1912.zones.sh
zone "." IN {
type hint;
file "named.ca";
};
zone "feifa.cn" {
type master;
file "feifa.cn.zone.sh";
};
[root@node1 ~]# vim /etc/named.rfc1912.zones.other
zone "." IN {
type hint;
file "named.ca";
};
zone "feifa.cn" {
type master;
file "feifa.cn.zone.other";
};
#修改权限
[root@node1 ~]# chgrp named /etc/named.rfc1912.zones.*
2.3 区域数据库文件
[root@node1 ~]# cp -p /var/named/named.localhost /var/named/feifa.cn.zone.bj
[root@node1 ~]# cp -p /var/named/named.localhost /var/named/feifa.cn.zone.sh
[root@node1 ~]# cp -p /var/named/named.localhost /var/named/feifa.cn.zone.other
[root@node1 ~]# vim /var/named/feifa.cn.zone.bj
$TTL 1D
@ IN SOA master admin.feifa.cn (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
master A 10.0.0.11
websrv A 192.168.100.15
www CNAME websrv
[root@node1 ~]# vim /var/named/feifa.cn.zone.sh
$TTL 1D
@ IN SOA master admin.feifa.cn (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
master A 10.0.0.11
websrv A 10.0.0.15
www CNAME websrv
[root@node1 ~]# vim /var/named/feifa.cn.zone.other
$TTL 1D
@ IN SOA master admin.feifa.cn (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
master A 10.0.0.11
websrv A 127.0.0.1
www CNAME websrv
#赋权、检查配置、启动(加载配置rndc reload)
[root@node1 ~]# chgrp named /var/named/feifa.cn.zone.*
[root@node1 ~]# named-checkconf
[root@node1 ~]# systemctl restart named
3.创建web服务
# 这里只创建了2台服务器other没创建
[root@node4 ~]# yum -y install httpd
[root@node4 ~]# echo www.feifa.cn in BeiJing > /var/www/html/index.html
[root@node4 ~]# systemctl start httpd
[root@node5 ~]# yum -y install httpd
[root@node5 ~]# echo www.feifa.cn in ShangHai > /var/www/html/index.html
[root@node5 ~]# systemctl start httpd
4.客户端测试
[root@node2 ~]# curl www.feifa.cn
www.feifa.cn in BeiJing
[root@node3 ~]# curl www.feifa.cn
www.feifa.cn in ShangHai
标签:02,named,cn,zone,09,feifa,DNS,node1,root
From: https://www.cnblogs.com/feifa/p/16054330.html