/etc/resolv.conf文件中的search項作用
resolv.conf文件中有search項時,主機名解析規則順序:
DNS配置文件如下:
# cat /etc/resolv.conf ; generated by /usr/sbin/dhclient-script search aqiyi.domain aqiyi.virtual ksc.com nameserver 8.8.8.8
例1:查詢主機名,因為主機名后面沒有點,就認為是主機名,所以先添加search里的每一項依次組成FQDN(完全合格域名)來查詢,完全合格域名查詢未找到,就再認為主機名是完全合格域名來查詢。
# host -a testttttttttt Trying "testttttttttt.aqiyi.domain" Trying "testttttttttt.aqiyi.virtual" Trying "testttttttttt.ksc.com" ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14314 ;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;testttttttttt.ksc.com. IN ANY ;; ANSWER SECTION: testttttttttt.ksc.com. 3599 IN A 69.172.201.153 testttttttttt.ksc.com. 3599 IN NS ns1.uniregistrymarket.link. testttttttttt.ksc.com. 3599 IN NS ns2.uniregistrymarket.link. testttttttttt.ksc.com. 3599 IN SOA ns1.uniregistrymarket.link. hostmaster.hostingnet.com. 1555555555 10800 3600 604800 86400 testttttttttt.ksc.com. 3599 IN MX 1 mx247.in-mx.com. testttttttttt.ksc.com. 3599 IN MX 1 mx247.in-mx.net. Received 230 bytes from 8.8.8.8#53 in 625 ms
例2:查詢主機名,因為主機名中有點(不是末尾有點),就認為是FQDN(完全合格域名)來查詢。
# host -a testttttttttt.com Trying "testttttttttt.com" Host testttttttttt.com not found: 3(NXDOMAIN) Received 108 bytes from 8.8.8.8#53 in 43 ms Received 108 bytes from 8.8.8.8#53 in 43 ms
如何保持resolv.conf文件內容不被修改 (CentOS7)
當文件被dhcp服務管理時。通過dhcp配置文件設置dns地址和默認搜索域
# vim etc/dhcp/dhclient.conf interface "eth0" { supersede domain-name-servers 8.8.8.8 ; supersede domain-name "aqiyi.domain aqiyi.virtual" ; }
cat /etc/resolv.conf ; generated by /usr/sbin/dhclient-script search aqiyi.domain aqiyi.virtual nameserver 8.8.8.8