network-tools について
管理者や開発者向けの Linux ネットワーク診断スキルです。一般的なコマンドラインツールを使い、設定、接続性、ポート、HTTP、パケット取得、性能の調査を扱います。
主な機能
- 01IP アドレスとルートの確認
- 02接続性と DNS のテスト
- 03ポートと接続の確認
- 04HTTP リクエストとダウンロード
- 05トラフィックの取得と監視
- 06ネットワーク性能の診断
活用シーン
- 01ポートを使用中のプロセスの特定
- 02ホストやサービスに接続できない原因の調査
- 03経路の追跡とタイムアウトの調査
- 04トラフィックと帯域使用量の確認
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ chaterm/ terminal-skills --skill network-toolsインストール後、Claude Code で/network-toolsを入力して読み込まれたか確認します。
詳細
ネットワークツールと診断
概要
Linux のネットワーク診断、ポートスキャン、トラフィック分析、その他のツールの使用方法を説明します。
ネットワーク設定
設定の表示
# IP address
ip addr
ip a
ifconfig # Legacy command
# Routing table
ip route
route -n
netstat -rn
# DNS configuration
cat /etc/resolv.conf
systemd-resolve --status
ネットワークの設定
# Temporary IP configuration
ip addr add 192.168.1.100/24 dev eth0
ip addr del 192.168.1.100/24 dev eth0
# Enable/Disable interface
ip link set eth0 up
ip link set eth0 down
# Add route
ip route add 10.0.0.0/8 via 192.168.1.1
ip route del 10.0.0.0/8
接続テスト
ping
ping hostname
ping -c 4 hostname # Send 4 packets
ping -i 0.2 hostname # 0.2 second interval
ping -s 1000 hostname # Specify packet size
traceroute
traceroute hostname
traceroute -n hostname # Don't resolve hostnames
traceroute -T hostname # Use TCP
mtr hostname # Real-time trace
DNS クエリ
nslookup hostname
dig hostname
dig +short hostname
dig @8.8.8.8 hostname # Specify DNS server
host hostname
ポートと接続
ss コマンド(推奨)
# Listening ports
ss -tlnp # TCP listening
ss -ulnp # UDP listening
ss -tlnp | grep :80
# All connections
ss -tanp # TCP connections
ss -s # Statistics
# Filter
ss -t state established
ss -t dst 192.168.1.1
ss -t sport = :80
netstat コマンド
netstat -tlnp # TCP listening
netstat -ulnp # UDP listening
netstat -anp # All connections
netstat -s # Statistics
lsof によるネットワーク確認
lsof -i # All network connections
lsof -i :80 # Specific port
lsof -i tcp # TCP connections
lsof -i @192.168.1.1 # Specific host
HTTP ツール
curl
# Basic request
curl http://example.com
curl -I http://example.com # Headers only
curl -v http://example.com # Verbose output
# POST request
curl -X POST -d "data=value" http://example.com
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://example.com
# Download
curl -O http://example.com/file.zip
curl -o output.zip http://example.com/file.zip
# Authentication
curl -u user:pass http://example.com
curl -H "Authorization: Bearer token" http://example.com
wget
wget http://example.com/file.zip
wget -c http://example.com/file.zip # Resume download
wget -r http://example.com # Recursive download
wget --mirror http://example.com # Mirror site
パケットキャプチャ
tcpdump
# Basic capture
tcpdump -i eth0
tcpdump -i any
# Filter
tcpdump -i eth0 port 80
tcpdump -i eth0 host 192.168.1.1
tcpdump -i eth0 'tcp port 80 and host 192.168.1.1'
# Save/Read
tcpdump -i eth0 -w capture.pcap
tcpdump -r capture.pcap
# Display content
tcpdump -i eth0 -A port 80 # ASCII
tcpdump -i eth0 -X port 80 # Hexadecimal
トラフィックの監視
# Real-time traffic
iftop
iftop -i eth0
# By process
nethogs
nethogs eth0
# Bandwidth test
iperf3 -s # Server
iperf3 -c server_ip # Client
よくあるシナリオ
シナリオ 1:ポートの使用状況のトラブルシューティング
# Check port usage
ss -tlnp | grep :8080
lsof -i :8080
# Find process and handle
kill -9 PID
# Or
fuser -k 8080/tcp
シナリオ 2:サービスの接続性テスト
# TCP port test
nc -zv hostname 80
telnet hostname 80
# HTTP service test
curl -I http://hostname
curl -w "HTTP Code: %{http_code}\nTime: %{time_total}s\n" -o /dev/null -s http://hostname
シナリオ 3:ネットワークパフォーマンスの診断
# Latency test
ping -c 100 hostname | tail -1
# Route analysis
mtr --report hostname
# Bandwidth test
iperf3 -c server -t 30
トラブルシューティング
| 問題 | 解決策 |
|---|---|
| ネットワークに到達できない | ping、traceroute を実行し、ルーティングを確認します |
| DNS 解決に失敗する | dig、nslookup を実行し、resolv.conf を確認します |
| ポートに到達できない | ss -tlnp を実行し、ファイアウォールを確認します |
| 接続がタイムアウトする | mtr、tcpdump でパケットをキャプチャします |
| 帯域幅が不足している | iftop、iperf3 でテストします |
コメント
Markdown 対応