1. 程式人生 > >/etc/resolv.conf檔案中的search項作用

/etc/resolv.conf檔案中的search項作用

resolv.conf檔案中有search項時,主機名解析規則順序:
DNS配置檔案如下:

# vi /etc/resolv.conf
# Generated by NetworkManager
search openstack.local dev.com example.local
nameserver 192.168.122.21

例1:查詢主機名,因為主機名後面沒有點,就認為是主機名,所以先新增search裡的每一項依次組成FQDN(完全合格域名)來查詢,完全合格域名查詢未找到,就再認為主機名是完全合格域名來查詢。

# host -a centos7-bind-1
Trying "centos7-bind-1.openstack.local"
Trying "centos7-bind-1.dev.com" Trying "centos7-bind-1.example.local" Trying "centos7-bind-1" ;; connection timed out; no servers could be reached

例2:查詢主機名,因為主機名中有點(不是末尾有點),就認為是完全合格域名,先用它來查詢,查詢失敗就把它當成是主機名來進行,新增search裡的每一項組成FQDN(完全合格域名)來查詢。

# host -a centos7-bind-1.com
Trying "centos7-bind-1.com"
Received 109
bytes from 192.168.122.21#53 in 177 ms Trying "centos7-bind-1.com.openstack.local" Trying "centos7-bind-1.com.dev.com" Trying "centos7-bind-1.com.example.local" Host centos7-bind-1.com not found: 3(NXDOMAIN) Received 125 bytes from 192.168.122.21#53 in 55 ms

例3:查詢主機名,因為主機名中末尾有點,則認為是完全合格域名,只用它來查詢(不會再新增search裡的每一項)。查詢次數會與search裡項域名個數有關。

# host -a centos7-bind-1.
Trying "centos7-bind-1"
;; connection timed out; trying next origin
Trying "centos7-bind-1"
;; connection timed out; trying next origin
Trying "centos7-bind-1"
;; connection timed out; trying next origin
Trying "centos7-bind-1"
;; connection timed out; no servers could be reached

DNS查詢工具:host命令介紹
用法:host [-a] FQDN [server]
host -l domain [server]
-a引數:顯示查詢的所有詳細資訊。
-l引數:如果後面的domain允許allow-transfer時,則列出該domain所管理的所有主機資料。
server引數:這個引數可有可無,當想要利用非 /etc/resolv.conf 內的DNS主機,來查詢主機名與 IP 的對應時,就可以利用這個引數了。

host命令使用例(列出該domain所管理的所有主機資料):

# host -l example.local  192.168.122.84
Using domain server:
Name: 192.168.122.84
Address: 192.168.122.84#53
Aliases: 

example.local name server ns.example.local.
dns.example.local has address 192.168.123.10
ns.example.local has address 192.168.122.84
ns.example.local has IPv6 address ::1
sss.example.local has address 192.168.123.9
www.example.local has address 192.168.123.8