欢迎各位兄弟 发布技术文章
这里的技术是共享的
reslov.conf中的search主要是用来补全hostname的,有时候域名太长,可以做一个短域名做主机名字,但是DNS解析需要的是FQDN,而在resolv.conf中设置search能进行补全。
vim /etc/hosts 42.120.7.71 www
ping www能通,返回就是42.120.7.71,ping会首先解析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步
来自 http://www.firefoxbug.com/index.php/archives/2375/
/etc/resolv.conf中关键字search和domain的作用
/etc/resolv.conf中关键字search和domain的作用
摘要:domain声明主机的域名。很多程序用到它,如邮件系统;当为没有域名的主机进行DNS查询时,也要用到。如果没有域名,主机名将被使用,删除所有在第一个点(.)前面的内容。search它的多个参数指明域名查询顺序。当要查询没有域名的主机,主机将在由search声明的域中分别查找。domain和search不能共存;如果同时存在,后面出现的将会被使用。下面的说明更清晰在/etc/resolv.conf配置文件:domain和search作用是一样的domainlinpro.nose
domain 声明主机的域名。很多程序用到它,如邮件系统;当为没有域名的主机进行DNS查询时,也要用到。如果没有域名,主机名将被使用,删除所有在第一个点( . )前面的内容。
search 它的多个参数指明域名查询顺序。当要查询没有域名的主机,主机将在由search 声明的域中分别查找。domain和search 不能共存;如果同时存在,后面出现的将会被使用。
下面的说明更清晰
在/etc/resolv.conf 配置文件:domain 和search作用是一样的
domain linpro.no
search linpro.no uio.no ifi.uio.no
domain function:
Had I typed telnet math.uio.no. with the trailing dot,the resolver would have known it was an FQDN and would have lookedupmath.uio.no at once, without trying to append thespecified domain first. Not all applications are tolerant of thetrailing dot, though, so it can't always be specified.
search function:
When ssh gram is executed, the resolver first looks forgram.linpro.no, which does not exist; thengram.uio.no, which does not exist, either; and finallygram.ifi.uio.no, which will succeed because it doesexist