解析域名對應的IP地址和別名等信息
host [選項] [主機名或IP] [server]
-a
:列出該主機詳細的各項主機名稱設定資料
server
:host命令默認是使用/etc/resolv.conf
文件中的 DNS 主機來查詢的,若設置該參數,則使用這裏設置的 DNS 主機進行查詢。
host 域名
[root@10 vagrant]# host www.baidu.com www.baidu.com is an alias for www.a.shifen.com. www.a.shifen.com has address 61.135.169.125 www.a.shifen.com has address 61.135.169.121
host -a 域名
[root@10 vagrant]# host -a www.baidu.com Trying "www.baidu.com" ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29562 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 5, ADDITIONAL: 5 ;; QUESTION SECTION: ;www.baidu.com. IN ANY ;; ANSWER SECTION: www.baidu.com. 1000 IN CNAME www.a.shifen.com. ;; AUTHORITY SECTION: baidu.com. 52656 IN NS ns7.baidu.com. baidu.com. 52656 IN NS ns3.baidu.com. baidu.com. 52656 IN NS ns2.baidu.com. baidu.com. 52656 IN NS ns4.baidu.com. baidu.com. 52656 IN NS dns.baidu.com. ;; ADDITIONAL SECTION: dns.baidu.com. 52853 IN A 202.108.22.220 ns2.baidu.com. 65473 IN A 61.135.165.235 ns3.baidu.com. 52760 IN A 220.181.37.10 ns4.baidu.com. 65473 IN A 220.181.38.10 ns7.baidu.com. 53740 IN A 180.76.76.92 Received 228 bytes from 10.0.2.3#53 in 9 ms
題外話:從上面能夠看出www.baidu.com
經過 CNAME 映射到www.a.shifen.com
,可是爲何咱們沒法直接訪問www.a.shifen.com
呢?
Web應用防火牆或高防IP生產的CNAME域名,是用於DNS解析的,不能直接訪問。服務器
host 域名 DNS主機名或IP
[root@10 vagrant]# host www.baidu.com 168.95.1.1 Using domain server: Name: 168.95.1.1 Address: 168.95.1.1#53 Aliases: www.baidu.com is an alias for www.a.shifen.com. www.a.shifen.com has address 180.97.33.108 www.a.shifen.com has address 180.97.33.107 [root@10 vagrant]# host www.baidu.com dns.hinet.net Using domain server: Name: dns.hinet.net Address: 168.95.1.1#53 Aliases: www.baidu.com is an alias for www.a.shifen.com. www.a.shifen.com has address 180.97.33.108 www.a.shifen.com has address 180.97.33.107 [root@10 vagrant]# host www.baidu.com 8.8.8.8 Using domain server: Name: 8.8.8.8 Address: 8.8.8.8#53 Aliases: www.baidu.com is an alias for www.a.shifen.com. www.a.shifen.com has address 61.135.169.121 www.a.shifen.com has address 61.135.169.125
域名解析工具,就是查DNS信息用的命令。使用 /etc/resolv.conf 這個文件做爲 DNS 服務器的來源選擇。
nslookup [主機名或IP]
nslookup 域名
[root@10 vagrant]# nslookup www.baidu.com Server: 10.0.2.3 Address: 10.0.2.3#53 Non-authoritative answer: Name: www.baidu.com Address: 61.135.169.121 Name: www.baidu.com Address: 61.135.169.125
並非全部的IP地址都能解析成功
nslookup IP
[root@10 vagrant]# nslookup 168.95.1.1 Server: 10.0.2.3 Address: 10.0.2.3#53 Non-authoritative answer: 1.1.95.168.in-addr.arpa name = dns.hinet.net. Authoritative answers can be found from: 95.168.in-addr.arpa nameserver = ans1.hinet.net. 95.168.in-addr.arpa nameserver = ans2.hinet.net. ans1.hinet.net internet address = 168.95.192.15 ans1.hinet.net has AAAA address 2001:b000:168::1:100:1 ans2.hinet.net internet address = 168.95.1.15 ans2.hinet.net has AAAA address 2001:b000:168::2:100:1
nslookup server
[root@10 vagrant]# nslookup server Server: 10.0.2.3 Address: 10.0.2.3#53 ** server can't find server: NXDOMAIN
域名查詢工具,能夠用來測試域名系統工做是否正常。網絡
功能與
nslookup
相似,建議使用dig
來取代nslookup
dom
若系統默認沒有 dig
命令,則使用下面命令進行安裝。工具
yum install bind-utils
dig [選項] [主機名]
@<DNS服務器IP>
:dig命令默認使用/etc/resolv.conf
文件中的 DNS 主機來解析域名,若設置該參數,則使用這裏設置的 DNS 主機進行解析。
-b <IP地址>
:當主機具備多個IP地址,指定使用本機的哪一個IP地址向域名服務器發送域名查詢請求。
[root@10 tmp]# dig www.baidu.com ; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> www.baidu.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50280 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 5, ADDITIONAL: 6 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.baidu.com. IN A ;; ANSWER SECTION: www.baidu.com. 1096 IN CNAME www.a.shifen.com. www.a.shifen.com. 290 IN A 61.135.169.121 www.a.shifen.com. 290 IN A 61.135.169.125 ;; AUTHORITY SECTION: a.shifen.com. 34 IN NS ns3.a.shifen.com. a.shifen.com. 34 IN NS ns4.a.shifen.com. a.shifen.com. 34 IN NS ns1.a.shifen.com. a.shifen.com. 34 IN NS ns5.a.shifen.com. a.shifen.com. 34 IN NS ns2.a.shifen.com. ;; ADDITIONAL SECTION: ns1.a.shifen.com. 411 IN A 61.135.165.224 ns2.a.shifen.com. 435 IN A 180.149.133.241 ns3.a.shifen.com. 431 IN A 61.135.162.215 ns4.a.shifen.com. 431 IN A 115.239.210.176 ns5.a.shifen.com. 435 IN A 119.75.222.17 ;; Query time: 11 msec ;; SERVER: 10.0.2.3#53(10.0.2.3) ;; WHEN: Wed May 16 08:40:42 UTC 2018 ;; MSG SIZE rcvd: 271
HEADER(標題):顯示查詢的內容有哪些,包括1個 QUERY, 3個 ANSWER 及5個AUTHORITY。
QUESTION(問題):顯示所要查詢的內容。
ANSWER(回答):依據剛剛的 QUESTION 去查詢所獲得的結果。
AUTHORITY(驗證):從這裏咱們能夠知道 www.baidu.com 是由 哪些DNS服務器提供的ANSWER。
[root@10 tmp]# dig @168.95.1.1 www.baidu.com ; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> @168.95.1.1 www.baidu.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48040 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 3072 ;; QUESTION SECTION: ;www.baidu.com. IN A ;; ANSWER SECTION: www.baidu.com. 1034 IN CNAME www.a.shifen.com. www.a.shifen.com. 241 IN A 180.97.33.107 www.a.shifen.com. 241 IN A 180.97.33.108 ;; Query time: 70 msec ;; SERVER: 168.95.1.1#53(168.95.1.1) ;; WHEN: Wed May 16 08:39:13 UTC 2018 ;; MSG SIZE rcvd: 101