在用來解析DNS的程式和指令有很多。今天就來介紹幾個比較常用的指令吧。
host、 nslookup、dig
host :
[root@localhost ~]# host blog.faq-book.com blog.faq-book.com has address 118.169.212.29 ç 此為IP |
[root@localhost ~]# host -a blog.faq-book.com #-a :代表列出該主機所有的相關資訊,包括 IP、TTL 與除錯訊息 #-l :若後面接的domain 設定允許 allow-transfer 時,則列出該 domain 所管理的 所有主機名稱對應資料 #server:這個參數可有可無,當想要利用非 /etc/resolv.conf 內的 DNS 主機 來查詢主機名稱與 IP 的對應時,就可以利用這個參數了
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64139 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;blog.faq-book.com. IN ANY ;; ANSWER SECTION: blog.faq-book.com. 913 IN A 118.169.212.29 Received 51 bytes from 8.8.8.8#53 in 9 ms ç 從8.8.8.8解析過來的 |
[root@localhost ~]# host bolg.faq-book.com 112.133.144.133 #強制使用112.133.144.133 DNS主機查詢 Using domain server: Name: 112.133.144.133 Address: 112.133.144.133#53 Host bolg.faq-book.com.localdomain not found: 5(REFUSED) |
nslookup :
使用方式有兩種
1. 可以直接在 nslookup 加上待查詢的主機名稱或者是 IP
[root@localhost ~]# nslookup blog.faq-book.com Server: 8.8.8.8 Address: 8.8.8.8#53 #因為在/etc/reslov.conf的第一組DNS是設8.8.8.8 google的,所以這邊會是先抓8.8.8.8 Non-authoritative answer: Name: blog.faq-book.com Address: 118.169.212.29 |
2. 如果在 nslookup 後面沒有加上任何主機名稱或 IP,會進入 nslookup 的查詢功能
在 nslookup 的查詢功能當中,可以輸入其他參數來進行特殊查詢,例如:
set type=any :列出所有的資訊『正解方面設定檔』
set type=mx :列出與 mx 相關的資訊
[root@localhost ~]# nslookup > 118.169.212.29 #反解的查詢 Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: 29.212.169.118.in-addr.arpa name = blog.faq-book.com. Authoritative answers can be found from: ————————————————————————————— > blog.faq-book.com #正解的查詢 Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: blog.faq-book.com Address: 118.169.212.29 ————————————————————————————– > set type=any > blog.faq-book.com Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: blog.faq-book.com Address: 118.169.212.29 Non-authoritative answer: blog.faq-book.com nameserver = dns1.name-services.com. blog.faq-book.com nameserver = dns2.name-services.com. blog.faq-book.com nameserver = dns3.name-services.com. blog.faq-book.com nameserver = dns4.name-services.com. blog.faq-book.com nameserver = dns5.name-services.com. Authoritative answers can be found from: >exit |
dig : (以後此指令會很常用到)
1. 不加任何參數直接查詢,查詢中出現以下幾點解釋:
QUESTION SECTION : 顯示查詢的內容。
ANSWER SECTION : 依據QUESTION 查詢所得到的結果。因此所回答的為該查詢的IP。
AUTHORITY SECTION : 此為驗證,在這邊可以看到所查詢的網址或IP是由哪一部DNS主機提供的。
此外,會看到1322這一個數字表示的為,允許查詢者能保留此筆記錄多久,若重覆查詢會發現此數字越來越少,最後會在重新抓取一次。
[root@localhost ~]# dig blog.faq-book.com ; <<>> DiG 9.3.6-P1-RedHat-9.3.6-16.P1.el5 <<>> blog.faq-book.com ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24225 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;blog.faq-book.com. IN A ;; ANSWER SECTION: blog.faq-book.com. 1322 IN A 118.169.212.29 ;; Query time: 10 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: Tue Aug 16 21:21:12 2011 ;; MSG SIZE rcvd: 51 |
2. 查詢 SOA 的相關資訊
因為在dig的輸出資料很多,所以通常都會分成多個部份回報。也剛好可使用此指令查看在,DNS設定部份是否正確
[root@localhost ~]# dig -t soa blog.faq-book.com ; <<>> DiG 9.3.6-P1-RedHat-9.3.6-16.P1.el5 <<>> -t soa blog.faq-book.com ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19804 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;blog.faq-book.com. IN SOA ;; ANSWER SECTION: blog.faq-book.com. 1800 IN SOA dns1.name-services.com. info.name-services.com. 2002050701 10001 1801 604801 181 ;; Query time: 189 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: Wed Aug 17 05:19:07 2011 ;; MSG SIZE rcvd: 90 |
3. 查詢反解的結果
[root@localhost ~]# dig -x 118.169.212.29 ; <<>> DiG 9.3.6-P1-RedHat-9.3.6-16.P1.el5 <<>> -x 118.169.212.29 ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46923 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;29.212.169.118.in-addr.arpa. IN PTR ;; ANSWER SECTION: 29.212.169.118.in-addr.arpa. 3587 IN PTR any-in-2015.1e100.net. ;; Query time: 41 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: Wed Aug 17 05:24:59 2011 ;; MSG SIZE rcvd: 70 |
評論
此文章尚無評論。