【Linux】resolv.conf中search作用

2023-05-13,,

   resolv.conf中的search主要是用来补全hostname的,有时候域名太长,可以做一个短域名做主机名字,但是DNS解析需要的是FQDN,而在resolv.conf中设置search能进行补全。


vim /etc/hosts
42.120.7.71 www

ping www能通,返回就是42.120.7.71ping会首先解析hosts


vim /etc/resolv.conf
search firefoxbug.net
nameserver 114.114.114.114







这时候nslookup www

Server:                114.114.114.114
Address:        114.114.114.114#53

Non-authoritative
answer:

Name:        
www.firefoxbug.net
Address: 42.120.7.71

看到没,search的作用就是补全要访问的短域名


正确的域名解析顺序是:

1. 查找/etc/hosts

2. 根据nameserver查找域名

3. 如果在nameserver查找不到域名就进行search补全,重新走1~2

《【Linux】resolv.conf中search作用.doc》

下载本文的Word格式文档,以方便收藏与打印。