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