network-tools
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNetwork Tools and Diagnostics
网络工具与诊断
Overview
概述
Linux network diagnostics, port scanning, traffic analysis and other tool usage skills.
Linux网络诊断、端口扫描、流量分析等工具的使用技巧。
Network Configuration
网络配置
View Configuration
查看配置
bash
undefinedbash
undefinedIP address
IP地址
ip addr
ip a
ifconfig # Legacy command
ip addr
ip a
ifconfig # 旧版命令
Routing table
路由表
ip route
route -n
netstat -rn
ip route
route -n
netstat -rn
DNS configuration
DNS配置
cat /etc/resolv.conf
systemd-resolve --status
undefinedcat /etc/resolv.conf
systemd-resolve --status
undefinedConfigure Network
配置网络
bash
undefinedbash
undefinedTemporary IP configuration
临时IP配置
ip addr add 192.168.1.100/24 dev eth0
ip addr del 192.168.1.100/24 dev eth0
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
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
undefinedip route add 10.0.0.0/8 via 192.168.1.1
ip route del 10.0.0.0/8
undefinedConnectivity Testing
连通性测试
ping
ping
bash
ping hostname
ping -c 4 hostname # Send 4 packets
ping -i 0.2 hostname # 0.2 second interval
ping -s 1000 hostname # Specify packet sizebash
ping hostname
ping -c 4 hostname # 发送4个数据包
ping -i 0.2 hostname # 间隔0.2秒
ping -s 1000 hostname # 指定数据包大小traceroute
traceroute
bash
traceroute hostname
traceroute -n hostname # Don't resolve hostnames
traceroute -T hostname # Use TCP
mtr hostname # Real-time tracebash
traceroute hostname
traceroute -n hostname # 不解析主机名
traceroute -T hostname # 使用TCP协议
mtr hostname # 实时追踪DNS Query
DNS查询
bash
nslookup hostname
dig hostname
dig +short hostname
dig @8.8.8.8 hostname # Specify DNS server
host hostnamebash
nslookup hostname
dig hostname
dig +short hostname
dig @8.8.8.8 hostname # 指定DNS服务器
host hostnamePorts and Connections
端口与连接
ss Command (Recommended)
ss命令(推荐)
bash
undefinedbash
undefinedListening ports
监听端口
ss -tlnp # TCP listening
ss -ulnp # UDP listening
ss -tlnp | grep :80
ss -tlnp # TCP监听端口
ss -ulnp # UDP监听端口
ss -tlnp | grep :80
All connections
所有连接
ss -tanp # TCP connections
ss -s # Statistics
ss -tanp # TCP连接
ss -s # 统计信息
Filter
过滤
ss -t state established
ss -t dst 192.168.1.1
ss -t sport = :80
undefinedss -t state established
ss -t dst 192.168.1.1
ss -t sport = :80
undefinednetstat Command
netstat命令
bash
netstat -tlnp # TCP listening
netstat -ulnp # UDP listening
netstat -anp # All connections
netstat -s # Statisticsbash
netstat -tlnp # TCP监听端口
netstat -ulnp # UDP监听端口
netstat -anp # 所有连接
netstat -s # 统计信息lsof Network
lsof网络相关
bash
lsof -i # All network connections
lsof -i :80 # Specific port
lsof -i tcp # TCP connections
lsof -i @192.168.1.1 # Specific hostbash
lsof -i # 所有网络连接
lsof -i :80 # 指定端口
lsof -i tcp # TCP连接
lsof -i @192.168.1.1 # 指定主机HTTP Tools
HTTP工具
curl
curl
bash
undefinedbash
undefinedBasic request
基础请求
curl http://example.com
curl -I http://example.com # Headers only
curl -v http://example.com # Verbose output
POST request
POST请求
curl -X POST -d "data=value" http://example.com
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://example.com
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
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
undefinedcurl -u user:pass http://example.com
curl -H "Authorization: Bearer token" http://example.com
undefinedwget
wget
bash
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 sitebash
wget http://example.com/file.zip
wget -c http://example.com/file.zip # 断点续传
wget -r http://example.com # 递归下载
wget --mirror http://example.com # 镜像站点Packet Capture
数据包捕获
tcpdump
tcpdump
bash
undefinedbash
undefinedBasic capture
基础捕获
tcpdump -i eth0
tcpdump -i any
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'
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
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
undefinedtcpdump -i eth0 -A port 80 # ASCII格式
tcpdump -i eth0 -X port 80 # 十六进制格式
undefinedTraffic Monitoring
流量监控
bash
undefinedbash
undefinedReal-time traffic
实时流量监控
iftop
iftop -i eth0
iftop
iftop -i eth0
By process
按进程统计流量
nethogs
nethogs eth0
nethogs
nethogs eth0
Bandwidth test
带宽测试
iperf3 -s # Server
iperf3 -c server_ip # Client
undefinediperf3 -s # 服务器端
iperf3 -c server_ip # 客户端
undefinedCommon Scenarios
常见场景
Scenario 1: Troubleshoot Port Usage
场景1:排查端口占用
bash
undefinedbash
undefinedCheck port usage
检查端口占用情况
ss -tlnp | grep :8080
lsof -i :8080
ss -tlnp | grep :8080
lsof -i :8080
Find process and handle
找到进程并处理
kill -9 PID
kill -9 PID
Or
或者
fuser -k 8080/tcp
undefinedfuser -k 8080/tcp
undefinedScenario 2: Test Service Connectivity
场景2:测试服务连通性
bash
undefinedbash
undefinedTCP port test
TCP端口测试
nc -zv hostname 80
telnet hostname 80
nc -zv hostname 80
telnet hostname 80
HTTP service test
HTTP服务测试
curl -I http://hostname
curl -w "HTTP Code: %{http_code}\nTime: %{time_total}s\n" -o /dev/null -s http://hostname
undefinedcurl -I http://hostname
curl -w "HTTP状态码: %{http_code}\n耗时: %{time_total}s\n" -o /dev/null -s http://hostname
undefinedScenario 3: Network Performance Diagnosis
场景3:网络性能诊断
bash
undefinedbash
undefinedLatency test
延迟测试
ping -c 100 hostname | tail -1
ping -c 100 hostname | tail -1
Route analysis
路由分析
mtr --report hostname
mtr --report hostname
Bandwidth test
带宽测试
iperf3 -c server -t 30
undefinediperf3 -c server -t 30
undefinedTroubleshooting
故障排查
| Problem | Solution |
|---|---|
| Network unreachable | |
| DNS resolution failed | |
| Port unreachable | |
| Connection timeout | |
| Insufficient bandwidth | |
| 问题 | 解决方案 |
|---|---|
| 网络不可达 | 使用 |
| DNS解析失败 | 使用 |
| 端口不可访问 | 使用 |
| 连接超时 | 使用 |
| 带宽不足 | 使用 |