linux下的dns(五)智能解析

简介

DNS根据源IP确定所属区域,然后依据这个区域把响应最快服务器域名解析出来。从而使得不同地域的用户解析不同。如CDN加速服务就应用dns智能解析。

实验目标

建设DNS智能解析服务器,对test.com域名做智能解析:
山东用户解析IP为 192.168.1.1
江苏的用户解析IP为 192.168.2.1
其他用户解析为192.168.3.1

实验步骤

1.修改配置文件
定义IP库,把IP库与区域关联,根据地域定义视图。

vim /etc/named.conf
options {
    listen-on port 53 { any; };
    directory     "/var/named";
};
//定义IP库
acl shandong { 
192.168.1.66;
};
acl jiangsu {
192.168.2.68;
};
//定义视图,通过IP匹配后,通过不同的区域数据库文件进行解析
view sd {
  match-clients { shandong; };
  zone "." IN {
    type hint;
    file "named.ca";
    };
   zone "test.com" IN {
    type master;
    file "test.com.zone.sd";
  };
};
view js {
  match-clients { jiangsu; };
  zone "." IN {
        type hint;
        file "named.ca";
};
   zone "test.com" IN {
        type master;
        file "test.com.zone.js";
};
};
view other {
  match-clients { any; };
  zone "." IN {
        type hint;
        file "named.ca";
};
zone "test.com" IN {
        type master;
        file "test.com.zone.other";
};
};

2.根据主配文件设置不同的区域数据库文件

cd /var/named
cp test.com.zone  test.com.zone.sd
cp test.com.zone  test.com.zone.js
cp test.com.zone  test.com.zone.other
chgrp named  test.com.zone.*
  • 分别设置区域文件
vim  /var/named/ayitula.com.zone.sd 
$TTL 1D
@    IN SOA    test.com. rname.invalid. (
                    0    ; serial
                    1D    ; refresh
                    1H    ; retry
                    1W    ; expire
                    3H )    ; minimum
    NS    www.test.com.
 www    A    192.168.1.1
vim  /var/named/ayitula.com.zone.js
$TTL 1D
@    IN SOA    test.com. rname.invalid. (
                    0    ; serial
                    1D    ; refresh
                    1H    ; retry
                    1W    ; expire
                    3H )    ; minimum
    NS    www.test.com.
 www    A    192.168.2.1
vim  /var/named/ayitula.com.zone.other
$TTL 1D
@    IN SOA    test.com. rname.invalid. (
                    0    ; serial
                    1D    ; refresh
                    1H    ; retry
                    1W    ; expire
                    3H )    ; minimum
    NS    www.test.com.
 www    A    192.168.3.1
```
c、测试
 nslookup www.test.com

你可能感兴趣的:(linux下的dns(五)智能解析)