ウェブサイト検索

DNS ルックアップのクエリに役立つ「host」コマンドの例


ホスト コマンドは、ドメイン名と IP アドレスを相互に変換する DNS ルックアップを実行するための、最小限で使いやすい CLI ユーティリティです。また、NS や MX などのさまざまな種類の DNS レコードの一覧表示と検証、ISP DNS サーバーとインターネット接続のテストと検証、スパムとブラックリストのレコード、特に DNS サーバーの問題の検出とトラブルシューティングにも使用できます。

この記事では、Linux で host コマンドをいくつかの便利な例とともに使用して DNS ルックアップを実行する方法を学びます。前回の記事では、DNS サーバーのテストとトラブルシューティング、および特定の DNS リソース レコード (RR) のクエリに最もよく使用される 8 つの Nslookup コマンドを紹介しました。

また、DNS 情報をクエリするための 10 個の Linux Dig (Domain Information Groper) コマンドについても説明しました。これは、Nslookup ツールによく似た機能です。ホスト ユーティリティも同様の方法で動作し、すべてではないにしてもほとんどの主流 Linux ディストリビューションにプレインストールされています。

そうは言っても、以下の 14 個のホスト コマンドを見てみましょう。

ドメイン IP アドレスを検索する

これは実行できる最も単純なホスト コマンドです。google.com などのドメイン名を指定するだけで、関連付けられた IP アドレスを取得できます。

$ host google.com

google.com has address 216.58.201.46
google.com has address 216.58.201.46
google.com has address 216.58.201.46
google.com has IPv6 address 2a00:1450:4009:80b::200e
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.

ドメインネームサーバーの検索

ドメイン ネーム サーバーを検索するには、-t オプションを使用します。

$ host -t ns google.com

google.com name server ns1.google.com.
google.com name server ns2.google.com.
google.com name server ns3.google.com.
google.com name server ns4.google.com.

ドメイン CNAME レコードの検索

ドメインの CNAME を確認するには、実行します。

$ host -t cname mail.google.com

mail.google.com is an alias for googlemail.l.google.com.

ドメイン MX レコードの検索

ドメインの MX レコードを検索します。

$ host -n -t mx google.com

ogle.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.

ドメイン TXT レコードの検索

ドメインの TXT レコードを検索します。

$ host -t txt google.com

google.com descriptive text "v=spf1 include:_spf.google.com ~all"

ドメイン SOA レコードの検索

-C フラグを使用すると、指定したゾーンのリストにあるすべての権威ネーム サーバーから、ホストにそのゾーンの SOA レコードの表示を試行させることができます。

$ host -C google.com

Nameserver 216.239.38.10:
	google.com has SOA record ns1.google.com. dns-admin.google.com. 156142728 900 900 1800 60
Nameserver 216.239.32.10:
	google.com has SOA record ns3.google.com. dns-admin.google.com. 156142728 900 900 1800 60
Nameserver 216.239.34.10:
	google.com has SOA record ns4.google.com. dns-admin.google.com. 156142728 900 900 1800 60
Nameserver 216.239.36.10:
	google.com has SOA record ns2.google.com. dns-admin.google.com. 156142728 900 900 1800 60

特定のネームサーバーのクエリ

特定のドメイン ネーム サーバーにクエリを実行します。

$ host google.com ns4.google.com

Using domain server:
Name: ns4.google.com
Address: 216.239.38.10#53
Aliases: 

google.com has address 172.217.19.46
google.com has address 172.217.19.46
google.com has address 172.217.19.46
google.com has IPv6 address 2a00:1450:4005:808::200e
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.

ドメインレコードとゾーンのすべての情報を検索する

ANY タイプのクエリを作成するには、-v オプションを設定するのと同じ -a (all) オプションを使用します。

$ host -a google.com

Trying "google.com"
;; ->>HEADER<

ドメインTTL情報の取得

ドメインの TTL 情報を確認します。

$ host -v -t a google.com

Trying "google.com"
;; ->>HEADER<

IPv4 または IPv6 のいずれかを使用します

-4 または -6 オプションを指定すると、ホストはそれぞれ IPv4 のみまたは IPV6 クエリ トランスポートのみを使用するようになります。

host -4 google.com
OR
host -6 google.com

非再帰的なクエリを実行する

-r オプションは非再帰的なクエリを実行します。このオプションを設定すると、ホストが作成するクエリ内のビットである RD (recursion Desired) がクリアされることに注意してください。

$ host -rR 5 google.com

google.com has address 216.58.201.46
google.com has address 216.58.201.46
google.com has address 216.58.201.46
google.com has IPv6 address 2a00:1450:4009:80b::200e
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.

ルックアップの UDP 再試行を設定する

デフォルトでは、UDP 試行回数は 1 です。これを変更するには、-R フラグを使用します。

$ host -R 5 google.com

google.com has address 216.58.201.46
google.com has address 216.58.201.46
google.com has address 216.58.201.46
google.com has IPv6 address 2a00:1450:4009:80b::200e
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.

クエリ時間を設定して応答を待つ

-W スイッチを使用すると、秒単位で指定した時間応答を待機するようにホストに指示できます。-w フラグを使用すると、ホストは永久に待機するようになります。返信の場合:

$ host -T -W 10 google.com

google.com has address 216.58.201.46
google.com has address 216.58.201.46
google.com has address 216.58.201.46
google.com has IPv6 address 2a00:1450:4009:80b::200e
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.

それでおしまい!この記事では、Linux でのホスト コマンドの使用方法をいくつかの役立つ例とともに学びました。このガイドに関するご意見がございましたら、以下のフィードバック フォームをご利用ください。