智能DNS实现

DNS实验主机:192.168.0.105

实现目的:根据不同的访问网络,将同一域名解析为不同的IP,实现类似于CDN的模式

#1、编辑DNS 配置文件,针对IP,进行不同调度配置,由于使用了view视图,所以根域的配置放到了/etc/named.rfc1912.zones...文件中
[root@ansible-manager ~]# vim /etc/named.conf
acl local {
   192.168.0.111;
   10.177.96.0/24;
};
acl public {   #除了上面local以外的网络 都使用此acl
   any;
};
options {
//    listen-on port 53 { localhost; };
  ...
//    allow-query     { any; };
};
...
view view_local {
   match-clients { local; };
   include "/etc/named.rfc1912.zones.local";
};
view view_public {
   match-clients { public; };
   include "/etc/named.rfc1912.zones.public";
};
include "/etc/named.root.key";

#2、配置视图 view_local和view_public的解析库文件

#复制修改 主要是不需要再进行文件权限修改了
[root@ansible-manager named]# cp -a /etc/named.rfc1912.zones  /etc/named.rfc1912.zones.local
[root@ansible-manager named]# cp -a /etc/named.rfc1912.zones  /etc/named.rfc1912.zones.public
#新增如下配置
[root@ansible-manager named]# vim  /etc/named.rfc1912.zones.local
...
zone "." IN {
        type hint;
        file "named.ca";
};
zone "xulx.com" IN {
    type master;
    file "local.xulx.com.zone";
};
...

[root@ansible-manager named]# vim  /etc/named.rfc1912.zones.public
...
zone "." IN {
        type hint;
        file "named.ca";
};
zone "xulx.com" IN {
    type master;
    file "public.xulx.com.zone";
};
...

#3、创建简单的域数据库文件
[root@ansible-manager named]# cd /var/named/

[root@ansible-manager named]# ll local.xulx.com.zone
-rw-r----- 1 root named 237 Apr 29 20:56 local.xulx.com.zone
[root@ansible-manager named]# cat  local.xulx.com.zone
$TTL 1D
@    IN SOA  cz.xulx.com. admin.cz.xulx.com. (
                    0    ; serial
                    1D    ; refresh
                    1H    ; retry
                    1W    ; expire
                    3H )    ; minimum
    NS    ns1
ns1     A       192.168.0.105
www     A       192.168.0.222

[root@ansible-manager named]# ll public.xulx.com.zone
-rw-r----- 1 root named 200 Apr 29 20:59 public.xulx.com.zone

[root@ansible-manager named]# cat public.xulx.com.zone
$TTL 1D
@    IN SOA  xulx.com. admin.xulx.com. (
                    0    ; serial
                    1D    ; refresh
                    1H    ; retry
                    1W    ; expire
                    3H )    ; minimum
    NS    ns1
ns1     A       192.168.0.105
www     A       47.103.54.59

#4、检测语法
[root@ansible-manager named]# named-checkconf
[root@ansible-manager named]#

[root@ansible-manager named]# named-checkzone  xulx.com  /var/named/local.xulx.com.zone
zone xulx.com/IN: loaded serial 0
OK
[root@ansible-manager named]# named-checkzone  xulx.com  /var/named/public.xulx.com.zone
zone xulx.com/IN: loaded serial 0
OK

#5、重启服务
[root@ansible-manager named]# systemctl  restart named

#6、在不同IP上进行测试,发现访问同一域名,分配到了不同的IP,实现了智能DNS
#在192.168.0.111上解析
[root@ansible_client2 ~]# dig www.xulx.com @192.168.0.105

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> www.xulx.com @192.168.0.105
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56038
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2


;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.xulx.com.            IN    A


;; ANSWER SECTION:
www.xulx.com.        86400    IN    A    192.168.0.222


;; AUTHORITY SECTION:
xulx.com.        86400    IN    NS    ns1.xulx.com.


;; ADDITIONAL SECTION:
ns1.xulx.com.        86400    IN    A    192.168.0.105
...

#在192.168.0.110上解析
[root@ansible-client1 ~]# dig www.xulx.com @192.168.0.105


; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> www.xulx.com @192.168.0.105
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25413
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2


;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.xulx.com.            IN    A


;; ANSWER SECTION:
www.xulx.com.        86400    IN    A    47.103.54.59


;; AUTHORITY SECTION:
xulx.com.        86400    IN    NS    ns1.xulx.com.


;; ADDITIONAL SECTION:
ns1.xulx.com.        86400    IN    A    192.168.0.105
...

你可能感兴趣的:(DNS)