Java教程

利用view实现智能DNS

本文主要是介绍利用view实现智能DNS,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

改配置文件

[root@localhost named]# vim /etc/named.conf 
acl beijingnet {
    172.31.0.0/16;
};

acl shenzhennet {
    192.168.0.0/24;
};

options {
//      listen-on port 53 { localhost; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        secroots-file   "/var/named/data/named.secroots";
        recursing-file  "/var/named/data/named.recursing";
//      allow-query     { any; };

view beijingview {
    match-clients { beijingnet; };
    include "/etc/named.rfc1912.zones.bj";
};

view shenzhenview {
    match-clients { shenzhennet; };
    include "/etc/named.rfc1912.zones.sz";
};

include "/etc/named.root.key";

拷贝文件

[root@localhost named]# cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.zones.bj
[root@localhost named]# cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.zones.sz

实现区域配置文件

beijing

[root@localhost named]# vim /etc/named.rfc1912.zones.bj
zone "." IN {
    type hint;
    file "named.ca";
};

zone "longxuan.vip" IN {
    type master;
    file "longxuan.vip.zone.bj";

shenzhen

[root@localhost named]# vim /etc/named.rfc1912.zones.sz
zone "." IN {
    type hint;
    file "named.ca";
};

zone "longxuan.vip" IN {
    type master;
    file "longxuan.vip.zone.sz";
};

拷贝文件

[root@localhost named]# cp -p longxuan.vip.zone longxuan.vip.zone.bj
[root@localhost named]# cp -p longxuan.vip.zone longxuan.vip.zone.sz

beijing

[root@localhost named]# vim longxuan.vip.zone.bj
$TTL 1D
@       IN SOA  master admin.longxuan.vip. (
                                2021050103      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
             NS      master
master       A       172.31.0.38
www          A       172.31.0.100

shenzhen

[root@localhost named]# vim longxuan.vip.zone.sz
$TTL 1D
@       IN SOA  master admin.longxuan.vip. (
                                2021050103      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
             NS      master
master       A       172.31.0.38             
www          A       192.168.0.200

重启服务

[root@localhost named]# rndc reload
server reload successful

客户端验证

# 这个网段过来就给分配到beijing
[19:28:02 root@sz-kx-centos8 ~]# dig www.longxuan.vip @172.31.0.100

# 这个网段过来就分配到shenzhen
[19:30:36 root@sz-kx-centos8 ~]# dig www.longxuan.vip @192.168.0.200
这篇关于利用view实现智能DNS的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!