哥使用Linux
分类: LINUX
2007-11-08 17:29:48
在实际的网络应用中,我们有时希望对于同一个Domain Name能够根据不同的请求IP地址/区域,解析到不同的对应IP地址,比如:有时对于企业内部网络和外部网络希望对同一域名解析到不同的IP地址以达到安全目的或者应用目的,又比如为了解决中国南北方电信/网通互访速度差异问题,您也会希望电信用户解析到的域名IP是位于电信网络中的服务器,网通用户亦然,使用户能够访问到临近的最快的服务器。
而这些应用都可以通过对DNS的简单配置达到,使用DNS达到这一目的有以下的优点:
使用DNS提供的view指令可以实现根据不同的IP范围来对同一个域名进行解析。
我们希望企业内部IP所解析到的IP地址为:12.34.56.78,外部IP段则解析到:87.65.43.21
//
// named.conf for Red Hat caching-nameserver
//
options {
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
/** If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
};
//
// a caching only nameserver config
//
controls {
inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
view "internal" {
match-clients { 10.0.0.0/24; };
zone "." IN {
type hint;
file "named.ca";
};
zone "testdns.org" {
type master;
file "db.internal";
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
};
view "other" {
match-clients { any; };
zone "." IN {
type hint;
file "named.ca";
};
zone "testdns.org" {
type master;
file "db.other";
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
};
include "/etc/rndc.key";
$TTL 86400
$ORIGIN testdns.org.
@ IN SOA ns1.testdns.org. webmaster.ns1.testdns.org. (
200512264
60
60
36000
86400 )
IN NS ns1.testdns.org.
@ IN A 10.0.0.1
ns1 IN A 10.0.0.1
www IN A 12.34.56.78
$TTL 86400 $ORIGIN testdns.org. @ IN SOA ns1.testdns.org. webmaster.ns1.testdns.org. ( 200512264 60 60 36000 86400 ) IN NS ns1.testdns.org. @ IN A 10.0.0.1 ns1 IN A 10.0.0.1 www IN A 87.65.43.21
通过这样的配置就可以实现我们之前所假想的功能了!测试:在内部网络中的一台电脑中将DNS服务器设置为10.0.0.1,之后ping ,会得到结果12.34.56.78;使用非内部网络的电脑设置好DNS:123.213.111.222,之后ping ,会得到结果87.65.43.21。
原文地址: