dig
網路
用法
dig [@server] <name> [type]直接向 DNS 伺服器提問並原樣顯示記錄;它繞過 /etc/hosts 和系統快取,所以結果可能和瀏覽器看到的不一樣,有些發行版還要先裝 dnsutils 或 bind-utils。
常用選項
| 選項 | 含義 |
|---|---|
| +short | Just the answer, one record per line. |
| @1.1.1.1 | Ask a specific resolver instead of the system one. |
| A / AAAA / MX / TXT / NS / CNAME | The record type goes last, with no dash. |
| +noall +answer | Trim the output to the answer section only. |
| -x <ip> | Reverse lookup, address to name. |
| +trace | Walk down from the root servers, which shows where a delegation breaks. |
| +ttlunits | Print TTLs as 1h30m instead of raw seconds. |
範例
dig +short example.comThe A records, nothing else.
dig @1.1.1.1 example.com MX +noall +answerMail records straight from a public resolver.
dig -x 8.8.8.8 +shortWhich name that address claims.
連不上的時候,這些能把範圍縮小——是名稱解析不了、沒有路由,還是連接埠被擋。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. dig 是做什麼的?
直接向 DNS 伺服器提問並原樣顯示記錄;它繞過 /etc/hosts 和系統快取,所以結果可能和瀏覽器看到的不一樣,有些發行版還要先裝 dnsutils 或 bind-utils。
Q. 怎麼寫?
dig [@server] <name> [type] —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 7 個,完整列表在 man dig。這條命令屬於網路。
相關命令
man 手冊: man dig