タイトル: nslookup ドメインのIP解決
SEOタイトル: nslookup コマンド完全ガイド (DNS A/MX/NS/TXT 解決)
| この記事の要点 |
|
nslookup とは
nslookup (Name Server Lookup) は、ドメイン名と IP アドレスの対応を DNS サーバに問い合わせるコマンドラインツールです。Windows / macOS / Linux 全 OS に標準搭載されており、ネットワーク調査やトラブルシュートの基本ツールです。
基本: A レコード解決
$ nslookup example.com
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
Name: example.com
Address: 93.184.216.34
# 説明:
# Server : 問い合わせ先 DNS サーバ (OS 設定の既定)
# Address : サーバ IP:Port (53)
# Non-authoritative : 権威サーバではなくキャッシュ DNS の応答
# Name : 解決対象
# Address : 結果 IP
レコードタイプ別の問い合わせ
| タイプ | 用途 | 例 |
|---|---|---|
| A | IPv4 アドレス | nslookup -type=a example.com |
| AAAA | IPv6 アドレス | nslookup -type=aaaa example.com |
| MX | メールサーバ | nslookup -type=mx example.com |
| NS | ネームサーバ | nslookup -type=ns example.com |
| TXT | SPF / DMARC / 検証 | nslookup -type=txt example.com |
| SOA | ゾーン責任 / Serial | nslookup -type=soa example.com |
| CNAME | 別名 | nslookup -type=cname www.example.com |
| PTR | 逆引き | nslookup 93.184.216.34 |
| SRV | サービス | nslookup -type=srv _ldap._tcp.example.com |
| ANY | 全件 (近年制限) | nslookup -type=any example.com |
使用例
# MX (どのサーバが example.com 宛メール受信するか)
nslookup -type=mx gmail.com
# gmail.com MX preference = 5, mail exchanger = gmail-smtp-in.l.google.com
# gmail.com MX preference = 10, mail exchanger = alt1.gmail-smtp-in.l.google.com
# NS (どこに権威サーバがあるか)
nslookup -type=ns example.com
# TXT (SPF / DMARC 確認)
nslookup -type=txt _dmarc.example.com
nslookup -type=txt example.com # SPF: "v=spf1 include:_spf.google.com ~all"
# 逆引き (IP -> ドメイン)
nslookup 8.8.8.8
# 8.8.8.8.in-addr.arpa name = dns.google.
# CNAME チェーン確認
nslookup -type=cname www.github.com
指定 DNS サーバへの問い合わせ
第 2 引数に DNS サーバ IP を指定すると、OS の設定とは違う DNS で解決できます。キャッシュ汚染や ISP の DNS 障害を切り分けるのに便利:
# Google Public DNS で問い合わせ
nslookup example.com 8.8.8.8
# Cloudflare で問い合わせ
nslookup example.com 1.1.1.1
# 社内 DNS で問い合わせ
nslookup intra.example.com 10.0.0.53
# 権威 NS に直接問い合わせ (キャッシュ無視)
nslookup -type=ns example.com 8.8.8.8
nslookup example.com a.iana-servers.net
対話モード
引数無しで起動すると対話モードに入り、複数のクエリを連続実行できます:
$ nslookup
> server 8.8.8.8 # 問い合わせ先変更
Default server: 8.8.8.8
Address: 8.8.8.8#53
> set type=mx # レコードタイプ変更
> gmail.com
gmail.com MX preference = 5 mail exchanger = gmail-smtp-in.l.google.com
...
> set type=a
> www.google.com
...
> set debug # 詳細表示
> set timeout=2 # タイムアウト調整
> exit # 終了
Windows での違い (PowerShell)
Windows では nslookup の他に PowerShell の Resolve-DnsName が使えます。こちらの方が出力が構造化されていて自動化に向きます:
# 基本
Resolve-DnsName example.com
# レコード指定
Resolve-DnsName example.com -Type MX
Resolve-DnsName example.com -Type TXT
# サーバ指定
Resolve-DnsName example.com -Server 8.8.8.8
# キャッシュをバイパス
Resolve-DnsName example.com -DnsOnly
# DNS キャッシュ確認
Get-DnsClientCache
Clear-DnsClientCache
# 古い方の Windows コマンド
ipconfig /displaydns
ipconfig /flushdns
Linux で dig を使う (推奨)
Linux では nslookup より dig が情報量・スクリプト適性ともに優れています:
# 基本
dig example.com
dig example.com MX
dig example.com TXT
# 指定 DNS サーバ
dig @8.8.8.8 example.com
# 答えだけ
dig +short example.com
dig +short example.com MX
# 詳細トレース (権威 NS まで辿る)
dig +trace example.com
# DNSSEC 検証
dig +dnssec example.com
# 全レコード
dig example.com ANY
# host コマンド (簡易)
host example.com
host -t MX example.com
# drill (drill is the new dig)
drill example.com
dig と nslookup の比較
| 項目 | nslookup | dig |
|---|---|---|
| 出力 | 人間向け | 詳細・パース容易 |
| +short | — | IP だけ取り出せる |
| +trace | — | 権威 NS まで辿れる |
| DNSSEC | — | +dnssec で検証 |
| 標準搭載 | ★ 全 OS | Windows は別途 |
| 非推奨 | 一部ドキュメント | — |
Windows でも dig は scoop install dig や BIND 同梱ツールで入ります。
トラブルシュート
| 症状 | 原因 | 対処 |
|---|---|---|
| 「サーバが見つかりません」 | OS の DNS 設定不正 | ipconfig /all 確認、固定 DNS 設定 |
| 古い IP が返る | DNS Cache | ipconfig /flushdns, systemd-resolve --flush-caches |
| 解決できるが繋がらない | FW / Route 問題 | ping / tracert 併用 |
| Non-authoritative answer のみ | キャッシュ DNS 経由 | 権威 NS に直接問い合わせ |
| TTL を見たい | nslookup では表示弱い | dig 利用 |
DNS Cache のフラッシュ
# Windows
ipconfig /flushdns
# Successfully flushed the DNS Resolver Cache.
# macOS
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
# Linux (systemd-resolved)
sudo systemd-resolve --flush-caches
sudo resolvectl flush-caches
# Linux (nscd)
sudo systemctl restart nscd
FAQ
Q: nslookup と ping の違い
A: nslookup は DNS 解決だけ、ping は解決後に ICMP Echo で疎通確認まで。ping が落ちても nslookup で解決成功なら DNS は OK、別の経路問題です。
Q: 出力の Non-authoritative answer って?
A: キャッシュ DNS が返した答えで、権威サーバ (Authoritative) からの直接応答ではない、という注記。Authoritative にしたい場合は権威 NS に直接問い合わせ。
Q: hosts ファイルの効果は?
A: nslookup はhosts を見ません。DNS だけ問い合わせます。OS の名前解決全体 (curl / ping 等) は hosts も見る。
Q: 同じドメインで複数 IP が返る
A: Round Robin DNS や CDN の地理的ルーティング。複数 A レコードを順に返してロード分散しています。