dig

ネットワーク

書き方

dig [@server] <name> [type]

DNS サーバーに直接尋ねて記録をそのまま見せます。/etc/hosts と系のキャッシュを飛ばすため、ブラウザーが見るものと違うことがあり、配布物によっては dnsutils か bind-utils の導入が必要です。

よく使うオプション

オプション意味
+shortJust the answer, one record per line.
@1.1.1.1Ask a specific resolver instead of the system one.
A / AAAA / MX / TXT / NS / CNAMEThe record type goes last, with no dash.
+noall +answerTrim the output to the answer section only.
-x <ip>Reverse lookup, address to name.
+traceWalk down from the root servers, which shows where a delegation breaks.
+ttlunitsPrint TTLs as 1h30m instead of raw seconds.

dig +short example.com

The A records, nothing else.

dig @1.1.1.1 example.com MX +noall +answer

Mail records straight from a public resolver.

dig -x 8.8.8.8 +short

Which 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