ネットワークトラブルシューティング
ネットワーク問題の診断と解決に使用するツールとテクニックを学びます。
目次
トラブルシューティングの流れ
基本的な診断ステップ
┌─────────────────────────────────────────────────────────────┐
│ ネットワーク問題の診断フロー │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. 物理層・リンク層 │
│ └── ip link show │
│ インターフェースは UP か? │
│ │
│ 2. ネットワーク層 │
│ └── ip addr show │
│ IPアドレスは設定されているか? │
│ └── ip route show │
│ ルーティングは正しいか? │
│ └── ping ゲートウェイ │
│ ゲートウェイに到達できるか? │
│ │
│ 3. 名前解決 │
│ └── cat /etc/resolv.conf │
│ DNSサーバーは設定されているか? │
│ └── dig example.com │
│ 名前解決できるか? │
│ │
│ 4. トランスポート層 │
│ └── ss -tuln │
│ サービスはリッスンしているか? │
│ └── telnet host port │
│ ポートに接続できるか? │
│ │
│ 5. アプリケーション層 │
│ └── curl http://example.com │
│ HTTPレスポンスは返ってくるか? │
│ │
└─────────────────────────────────────────────────────────────┘
接続確認ツール
ping
ICMP Echo を使った基本的な疎通確認です。
# 基本的な使い方
ping google.com
ping 8.8.8.8
# 回数指定
ping -c 5 google.com
# 間隔指定
ping -i 0.5 google.com
# パケットサイズ指定
ping -s 1500 google.com
# 出力例
# PING google.com (142.250.196.110): 56 data bytes
# 64 bytes from 142.250.196.110: icmp_seq=0 ttl=118 time=10.5 ms
# 64 bytes from 142.250.196.110: icmp_seq=1 ttl=118 time=9.8 ms
traceroute / tracepath
パケットの経路を確認します。
# traceroute
traceroute google.com
traceroute -n google.com # 名前解決なし
# tracepath(ICMP不要)
tracepath google.com
# mtr(リアルタイム表示)
mtr google.com
mtr -n google.com
# 出力例(traceroute)
# 1 192.168.1.1 1.234 ms
# 2 10.0.0.1 5.678 ms
# 3 * * * (応答なし)
# 4 142.250.196.110 10.123 ms
telnet / nc(netcat)
ポート接続確認に使用します。
# telnet
telnet example.com 80
# Trying 93.184.216.34...
# Connected to example.com.
# netcat(推奨)
nc -zv example.com 80
# Connection to example.com 80 port [tcp/http] succeeded!
# 複数ポートスキャン
nc -zv example.com 80-443
# タイムアウト指定
nc -zv -w 3 example.com 80
# UDPポート確認
nc -zuv example.com 53
curl / wget
HTTPレベルの確認に使用します。
# 基本
curl http://example.com
curl -I http://example.com # ヘッダーのみ
# 詳細情報
curl -v http://example.com
curl -w "%{http_code}\n" -o /dev/null -s http://example.com
# タイミング情報
curl -w "DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTotal: %{time_total}s\n" \
-o /dev/null -s http://example.com
# HTTPS証明書確認
curl -vI https://example.com 2>&1 | grep -A5 "Server certificate"
# プロキシ経由
curl -x http://proxy:8080 http://example.com
# wget
wget -q -O - http://example.com
wget --spider http://example.com
DNS診断
dig
DNS問い合わせの詳細を確認します。
# 基本
dig example.com
# 短縮表示
dig +short example.com
# 特定のレコードタイプ
dig example.com A
dig example.com MX
dig example.com TXT
dig example.com NS
# 特定のDNSサーバーを使用
dig @8.8.8.8 example.com
# トレース(再帰的解決の過程)
dig +trace example.com
# 逆引き
dig -x 8.8.8.8
# 出力例
# ;; ANSWER SECTION:
# example.com. 86400 IN A 93.184.216.34
#
# ;; Query time: 23 msec
# ;; SERVER: 8.8.8.8#53(8.8.8.8)
nslookup
# 基本
nslookup example.com
# 特定のDNSサーバー
nslookup example.com 8.8.8.8
# レコードタイプ指定
nslookup -type=MX example.com
host
# 基本
host example.com
# 詳細
host -v example.com
# 逆引き
host 8.8.8.8
DNS問題の診断
# 設定ファイル確認
cat /etc/resolv.conf
# ローカルホストファイル
cat /etc/hosts
# 名前解決順序
cat /etc/nsswitch.conf
# DNSキャッシュクリア(systemd-resolved)
sudo systemd-resolve --flush-caches
sudo systemd-resolve --statistics