host 命令在Linux和Solaris的行为不同(ndots)
今天遇到一些 dns client古怪的行为方式,这里做一个记录:
命令如下:
Linux
[root@crp-abc~]# host -v -t A -N1 lvsosprovsvc01.lvs 10.10.10.10
Trying “lvsosprovsvc01.lvs”
…
Host lvsosprovsvc01.lvs not found: 3(NXDOMAIN)
Received 111 bytes from 10.10.10.10#53 in 0 ms
Solaris
crp-xyz# host -v -t A -N1 lvsosprovsvc01.lvs 10.10.10.10
Trying “lvsosprovsvc01.lvs”
Received 111 bytes from 10.10.10.10#53 in 0 ms
Trying “lvsosprovsvc01.lvs.corp.abc.com”
Trying “lvsosprovsvc01.lvs.vip.corp.abc.com”
Trying “lvsosprovsvc01.lvs.qa.abc.com”
…
lvsosprovsvc01.lvs.qa.abc.com. 125 IN A 10.10.10.11
两机器的/etc/resolv.conf相同。
也就是说 同样是在尝试按照Absolute dns name 来解析lvsosprovsvc01.lvs(红字)失败后, Solaris下host命令继续尝试search domain list,直到最终找到结果,但是Linux却放弃了。
host命令的Manual page 中对 ndots的描述:
The -N option sets the number of dots that have to be in name for it to be considered absolute. The default value is that defined using the ndots statement in /etc/resolv.conf, or 1 if no ndots statement is present. Names with fewer dots are interpreted as relative names and will be searched for in the domains listed in the search or domain directive in /etc/resolv.conf.
host 命令的Manual page中对ndots的描述:
-N ndots Set the number of dots that have to be in name for it to be considered absolute. The default value is that defined using the ndots statement in /etc/resolv.conf, or 1 if no ndots statement is present. Names with fewer dots are inter-
preted as relative names and will be searched for in the domains listed in the search or domain directive in /etc/resolv.conf.
Manual中并没有明确对这种行为做出解释,是Linux下做的少了?还是Solaris下做的多了呢?
为了在Linux下避免这种行为,最好的解决办法就是将ndots修改为2,那么lvsosprovsvc01.lvs就永远不会被当成 Absolute name来对待,所以直接就会走search domain list进行匹配查询,直到找到结果。
关于/etc/resolv.conf中的search 参数也有一个tricky的地方,因为这个list最长只支持6个domain:
The search list is currently limited to six domains with a total of 256 characters.
我不知道有什么办法expand这个list,除了修改 host 命令源代码 include/resolv.h 中的这行。
#define MAXDNSRCH 6 /* max # domains in search path */
