DNS解決 · 2 min read · Sep 08, 2025
Linuxでdigコマンドを使用してDNSドメイン名を解決する

digコマンドは「Domain Information Groper」の略で、Linuxのネットワーク管理ツールであり、DNS(Domain Name System)サーバーにクエリを送信するために使用されます。これにより、ユーザーはドメイン名に関する情報(IPアドレス、メールサーバー(MXレコード)、その他のDNSリソースレコードなど)を取得できます。主にDNSの問題をトラブルシューティングするために使用され、digはクエリの応答時間や情報を提供したDNSサーバーを含む詳細な出力を提供します。その柔軟性と精度により、ネットワーク管理者がDNSの問題を診断し、ドメインの構成をテストし、nslookupのような基本的なコマンドと比較してDNSルックアップを実行するための好ましいツールとなっています。
digコマンドを使用してドメイン名を解決する
ドメインexample.comを解決する:
dig example.comドメインが解決できる場合、結果は次のようになります:
root@server1:~# dig howtoforge.com
; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> howtoforge.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50297
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;howtoforge.com. IN A
;; ANSWER SECTION:
howtoforge.com. 299 IN A 104.24.0.68
howtoforge.com. 299 IN A 104.24.1.68
;; Query time: 233 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Wed Aug 08 12:35:15 CEST 2024
;; MSG SIZE rcvd: 75digでローカルDNSサーバーにクエリを送信する方法
ローカルウェブサーバーがこのドメインの責任を持っているか確認するには、次のコマンドを使用します:
dig @localhost example.comdigでメールサーバー名を取得する
example.comのメールを処理するメールサーバーを知りたい場合は、次のコマンドを使用できます:
dig MX example.com結果は次のようになります:
root@server1:~# dig MX howtoforge.com
; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> MX howtoforge.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14115
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;howtoforge.com. IN MX
;; ANSWER SECTION:
howtoforge.com. 299 IN MX 10 mail.howtoforge.com.
;; Query time: 205 msec
;; SERVER: 8.8.4.4#53(8.8.4.4)
;; WHEN: Wed Aug 08 10:36:30 CEST 2024
;; MSG SIZE rcvd: 64digコマンドの詳細オプションを取得する
digコマンドのすべての利用可能なオプションを取得するには、次のコマンドを実行します:
dig --helpdigコマンドのマニュアルページには、より詳細な説明があります:
man dig以下は、digの使い方を明確に示すツールのマニュアルページからの抜粋です:
A typical invocation of dig looks like:
dig @server name type
where:
server
is the name or IP address of the name server to query. This can be an IPv4 address in
dotted-decimal notation or an IPv6 address in colon-delimited notation. When the supplied
server argument is a hostname, dig resolves that name before querying that name server.
If no server argument is provided, dig consults /etc/resolv.conf; if an address is found
there, it queries the name server at that address. If either of the -4 or -6 options are in
use, then only addresses for the corresponding transport will be tried. If no usable addresses
are found, dig will send the query to the local host. The reply from the name server that
responds is displayed.
name
is the name of the resource record that is to be looked up.
type
indicates what type of query is required — ANY, A, MX, SIG, etc. type can be any valid query
type. If no type argument is supplied, dig will perform a lookup for an A record.特定のセクションを出力表示から削除するようにdigコマンドを強制することもできます。たとえば、出力のコメント行の表示を切り替えたり、回答が返されたときのクエリの質問セクションを切り替えたりするには、+nocommentsおよび+noquestionオプションを使用します。
以下のスクリーンショットは、これらのオプションがどのように機能するかを示しています:

ドメインのネームサーバーを取得する
次に、digコマンドを使用してMXレコードのようにNSレコードをクエリできます。次のように実行します:
dig NS example.comこのコマンドが生成した出力は次のとおりです:

digコマンドでドメイン名のIPアドレスを取得する
サーバーのIPアドレスのみを表示するようにdigを設定するには、+shortオプションを使用します。
たとえば:
dig example.com +short複数のウェブサイト/サーバーを一度にクエリしたい場合は、ファイルに名前のリストを作成し、そのファイル名をdigコマンドの-fオプションに入力として渡すことができます。
-f file
Batch mode: dig reads a list of lookup requests to process from the given file. Each line in the
file should be organized in the same way they would be presented as queries to dig using the
command-line interface.以下はその例です:

新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。