在DNS中,泛域名(wildcard Resource Record)可以被认为是一种合成RR的机制,借助于它,DNS服务器可以响应本来不存在的域名的请求,它的设计初衷是用来把所有邮件都转发到一个邮件系统(当然,它除了用在MX类型的资源记录上外,还可以用在其他的资源记录上)。
一个典型的泛域名的格式是:
*.taobao.com 300 IN A 10.20.30.40
其中:
- *号必须是位于最左端的DNS
Lable,任何其他位置的‘*‘都不会被认为是泛域名,例如*taobao.com,shop.*.taobao.com以及*.taobao.com都不会被认为是泛域名
- anydomain是任何域名,但是anydomain不能包含*,同时它必须属于一个本域名服务器所服务的zone
上面的泛域名配置会使得对所有请求域名中以taobao.com结尾的A记录请求都返回10.20.30.40
需要注意的是:泛域名只匹配不存在的域名,如果这个域名存在,但是它的资源类型与请求资源类型不匹配,那么请求域名不会被再次做泛域名匹配
为了清楚地解释泛域名的匹配原则,RFC4592中引入了Closest Encloser 和 Source of Synthesis的概念:
Closest Encloser是zone中domain所组成的树中,与请求域名匹配了最多lable数的那个节点。换言之,Closest Encloser就是zone中已经存在的一个domain。
Source of Synthesis是zone中domain所组成的树中,Closest
Encloser的含有字符*的最亲子树(如果有的话),即:*.[Closest Encloser]
Source of
Synthesis不能保证能生成请求RR类型的结果,也就是说source of synthesis中可能没有资源记录,也可能没有请求所需要的资源记录
如果在域名匹配的过程中,source of synthesis为空,则没有与之匹配的泛域名
(借用RFC4592中的例子来说明泛域名的匹配原则)
假设有一个DNS zone有如下的资源记录:
$ORIGIN example. example. 3600 IN SOA <SOA RDATA> example. 3600 NS ns.example.com. example. 3600 NS ns.example.net. *.example. 3600 TXT "this is a wildcard" *.example. 3600 MX 10 host1.example. sub.*.example. 3600 TXT "this is not a wildcard" host1.example. 3600 A 192.0.2.1 _ssh.tcp.host1.example. 3600 SRV <SRV RDATA> _ssh.tcp.host2.example. 3600 SRV <SRV RDATA> subdel.example. 3600 NS ns.example.com. subdel.example. 3600 NS ns.example.net.
下面是一些请求域名和它对应的Closest Encloser和Source of synthesis:
1
2
3
4
5
6
7 |
QNAME Closest Encloser Source of Synthesis host3.example. example. *.example. _telnet._tcp.host1.example. _tcp.host1.example. no source _dns._udp.host2.example. host2.example. no source _telnet._tcp.host3.example. example. *.example. _chat._udp.host3.example. example. *.example. foobar.*.example. *.example. no source |
host3.example. A
它有对应的source of synthesis--*.example,但是对应的泛域名*.example中没有A记录,所以它的响应结果是:
no
error,answer为空
foo.bar.example. TXT
它对应的source of
synthesis--*.example,并且泛域名*.example中有TXT记录,所以它的响应结果是:
foo.bar.example. IN TXT
"this is a wildcard"
host1.example. MX
它匹配到了域名host1.example,但是host1.example中没有MX记录,所以它的响应结果是:
no-error, no data
sub.*.example. MX
这种带*的域名,只会把*当作一个普通字符去匹配,所以它的响应结果是:
no-error, no data
_telnet.tcp.host1.example SRV
它对应的closest encloser是tcp.host1.example,所以它匹配不到泛域名,响应结果为空
host.subdel.example. A
因为subdel.example是属于另外一个zone,根据rfc1034的4.3.2的step2-b,遇到本域名服务器服务的domain请求,则将跟这个domain相关的zone的信息添加到authority section中并返回
ghost.*.example. MX
不会匹配到泛域名*.example,因为泛域名的匹配是lable by lable的,并不是说*.example能匹配所有以example结尾的域名请求,它不能匹配*.example的subdomain。
原文:http://www.cnblogs.com/cobbliu/p/3655204.html