resolv.conf:search、domain、nameserver解释

管理员 Linuxresolv.conf:search、domain、nameserver解释已关闭评论43,3922字数 940阅读3分8秒阅读模式

resolv.conf是resolver类库使用的配置文件,每当一个程序需要通过域名来访问internet上面的其它主机时,需要利用该类库将域名转换成对应的IP,然后才可进行访问.

resolv.conf文件的配置选项不多,从man文档中看了半天,不理解domain和search使用来干嘛的。这里做个解释,防止以后忘了(环境:ubuntu12.04):文章源自运维生存时间-https://www.ttlsa.com/linux/resolv-conf-desc/

nameserver x.x.x.x该选项用来制定DNS服务器的,可以配置多个nameserver指定多个DNS。文章源自运维生存时间-https://www.ttlsa.com/linux/resolv-conf-desc/

domain mydomain.com这个用来指定本地的域名,在没有设置search的情况下,search默认为domain的值。这个值可以随便配,目前在我看来,domain除了当search的默认值外,没有其它用途。也就说一旦配置search,那domain就没用了。文章源自运维生存时间-https://www.ttlsa.com/linux/resolv-conf-desc/

search google.com baidu.com该选项可以用来指定多个域名,中间用空格或tab键隔开。它是干嘛的呢?文章源自运维生存时间-https://www.ttlsa.com/linux/resolv-conf-desc/

如:在没有配置该选项时,执行文章源自运维生存时间-https://www.ttlsa.com/linux/resolv-conf-desc/

#ping  new
sping: unknown host news

配置search google.com baidu.com后,再执行文章源自运维生存时间-https://www.ttlsa.com/linux/resolv-conf-desc/

#ping news
PING news.google.com (74.125.128.101) 56(84) bytes of data.
64 bytes from hg-in-f101.1e100.net (74.125.128.101): icmp_req=1 ttl=47 time=78.9 ms
64 bytes from hg-in-f101.1e100.net (74.125.128.101): icmp_req=2 ttl=47 time=63.6 ms

它就去ping news.google.com了。原来当访问的域名不能被DNS解析时,resolver会将该域名加上search指定的参数,重新请求DNS,直到被正确解析或试完search指定的列表为止。文章源自运维生存时间-https://www.ttlsa.com/linux/resolv-conf-desc/

由于news不能被DNS解析,所以去尝试news.google.com,被正常解析。如果没有被解析还会去尝试news.baidu.com。文章源自运维生存时间-https://www.ttlsa.com/linux/resolv-conf-desc/

参考链接:http://dns-learning.twnic.net.tw/bind/intro4.html文章源自运维生存时间-https://www.ttlsa.com/linux/resolv-conf-desc/ 文章源自运维生存时间-https://www.ttlsa.com/linux/resolv-conf-desc/

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
管理员
  • 本文由 发表于 18/07/2016 11:40:34
  • 转载请务必保留本文链接:https://www.ttlsa.com/linux/resolv-conf-desc/