智能DNS就是根据用户的来源地域,自动智能化判断来路IP返回给用户,而不需要用户进行选择。
智能DNS实现的主要功能:
比方一个企业的站点三个运营商的带宽都有:电信、联通、移动;同样来自三个不同 运营商网络的访问用户,假设电信用户访问企业网址的时候,智能DNS会自动根据IP判断,再从电信返回给电信用户,其他的也同理;
电信用户:访问 www.sina.com 返回 1.1.1.1;
联通用户:访问 www.sina.com 返回 2.2.2.2;
移动用户:访问 www.sina.com 返回 3.3.3.3;
acl:访问控制列表;把一个或多个地址归并一个命名的集合,随后通过此名称即可对此集全内的所有主机实现统一调用;
bind内置了四个四种ACL
any :允许所有主机节点查询;
none :拒绝所有主机节点查询;
localhost :仅允许本地接口网络主机查询;
localnet :本地子网所有IP;
也可以自定义ACL规则,示例如下:
#1.复杂acl规则定义 acl "ips" { <==定义一个名为ips的ACL 10.0.0.1; 10.0.0.2; 192.168.1.1; <==包含3个单个IP 172.16.1.0/24; ... }; #2.复杂acl规则定义 acl "all_rule" { <==定义一个名为all_rule的ACL "ips"; <==可以嵌套包含其他ACL 10.0.15.0/24; <==包含10.0.15.0子网中的所有IP !10.0.16.1/24; <==非10.0.16.1子网的IP {10.0.17.1;10.0.18.2;}; <==包含了一个IP组 localhost; <==本地网络接口IP(含实际接口IP和127.0.0.1) };
view 语句定义了视图功能,视图是BIND9提供的强大的新功能,允许DNS服务器根据不同的客户端,请求相同的域名,但返回不同的解析结果。
view的语法格式为:
view view_name [class] { <==view为声明关键字 ,后面加上自定义的view名称 match-clients { address_match_list } ; <==匹配的客户端ACL match-destinations { address_match_list } ; <==匹配访问的目标地址的ACL; match-recursive-only { yes_or_no } ; [ view_option; ...] };
view的功能的主要事项如下:
目标:
bind的配置文件如下:
[root@dns01 named]# cat /etc/named.conf options { listen-on port 53 { localhost; }; listen-on-v6 port 53 { localhost; }; 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"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { any; }; recursion yes; allow-recursion { 192.168.20.0/24; 192.168.50.0/24; }; allow-transfer {192.168.20.71;}; also-notify {192.168.20.71;}; dnssec-enable yes; dnssec-validation yes; bindkeys-file "/etc/named.root.key"; managed-keys-directory "/var/named/dynamic"; pid-file "/run/named/named.pid"; session-keyfile "/run/named/session.key"; }; logging { channel default_debug { file "data/named.run"; severity dynamic; }; }; acl "test-env" { <==定义ACL 192.168.20.17; }; acl "shengchan-env" { 192.168.20.30; }; view "test-env-view" { <==定义view match-clients { "test-env"; }; <==匹配客户端地址 zone "xuzhichao.com" IN { <==在view下定义区域配置文件 type master; file "xuzhichao.com.test.zone"; }; }; view "shengchan-env-view" { match-clients { "shengchan-env"; }; zone "xuzhichao.com" IN { type master; file "xuzhichao.com.shengchan.zone"; }; }; view "default" { zone "." IN { type hint; file "named.ca"; }; include "/etc/named.rfc1912.zones"; include "/etc/named.xuzhichao.com.zone"; }; include "/etc/named.root.key";
区域解析文件如下:
[root@dns01 named]# cat /var/named/xuzhichao.com.shengchan.zone $TTL 86400 xuzhichao.com. IN SOA ns1.xuzhichao.com. mail.xuzhichao.com. ( 2021071603 10800 900 604800 86400 ) xuzhichao.com. IN NS ns1.xuzhichao.com. xuzhichao.com. IN NS ns2.xuzhichao.com. ns1 IN A 192.168.20.70 ns2 IN A 192.168.20.71 xuzhichao.com. IN MX 10 mx1.xuzhichao.com. mx1 IN A 192.168.20.11 eip.xuzhichao.com. IN A 100.2.2.2 [root@dns01 named]# cat /var/named/xuzhichao.com.test.zone $TTL 86400 xuzhichao.com. IN SOA ns1.xuzhichao.com. mail.xuzhichao.com. ( 2021071603 10800 900 604800 86400 ) xuzhichao.com. IN NS ns1.xuzhichao.com. xuzhichao.com. IN NS ns2.xuzhichao.com. ns1 IN A 192.168.20.70 ns2 IN A 192.168.20.71 xuzhichao.com. IN MX 10 mx1.xuzhichao.com. mx1 IN A 192.168.20.11 eip.xuzhichao.com. IN A 100.1.1.1 #修改属组和权限: [root@dns01 named]# chgrp named /var/named/xuzhichao.com.test.zone [root@dns01 named]# chmod 640 /var/named/xuzhichao.com.test.zone [root@dns01 named]# chgrp named /var/named/xuzhichao.com.shengchan.zone [root@dns01 named]# chmod 640 /var/named/xuzhichao.com.shengchan.zone
检测语法,重启bind服务:
[root@dns01 named]# named-checkconf [root@dns01 named]# named-checkzone xuzhichao.com /var/named/xuzhichao.com.test.zone zone xuzhichao.com/IN: loaded serial 2021071603 OK [root@dns01 named]# named-checkzone xuzhichao.com /var/named/xuzhichao.com.shengchan.zone zone xuzhichao.com/IN: loaded serial 2021071603 OK
使用客户端测试效果:
#1.使用192.168.20.17的客户端进行测试: [root@xuzhichao ~]# dig eip.xuzhichao.com @192.168.20.70 +short 100.1.1.1 #2.使用192.168.20.30的客户端进行测试: [root@dns-son ~]# dig eip.xuzhichao.com @192.168.20.70 +short 100.2.2.2
根据不同的运营商地址返回不同的DNS解析结果:
//电信IP访问控制列表 acl "telecomip"{ telecom_IP; ... }; //联通IP访问控制列表 acl "netcomip"{ netcom_IP; ... }; view "telecom" { match-clients { "telecomip"; }; zone "ZONE_NAME" IN { type master; file "ZONE_NAME.telecom.zone"; }; }; view "netcom" { match-clients { "netcomip"; }; zone "ZONE_NAME" IN { type master; file "ZONE_NAME.netcom.zone"; }; }; view "default" { match-clients { any; }; zone "ZONE_NAME" IN { type master; file "ZONE_NAME.zone"; }; };