Overview
Skills related to TCP/IP protocol stack network diagnostics, connectivity testing, port troubleshooting, and more.
Connectivity Testing
# Ping 测试
ping -c 4 hostname
ping -i 0.2 hostname # 间隔 0.2 秒
# 路由追踪
traceroute hostname
traceroute -n hostname # 不解析域名
mtr hostname # 实时追踪
Port Connectivity
telnet hostname 80 nc -zv hostname 80 nc -zv hostname 80-100 # port range
## 网络配置
```bash
# 查看网络接口
ip addr
ip link show
ifconfig # 传统命令
# 查看路由表
ip route
route -n
netstat -rn
# 查看 ARP 表
ip neigh
arp -a
# DNS 查询
nslookup hostname
dig hostname
dig +short hostname
host hostname
Ports and Connections
# 查看监听端口
ss -tlnp # TCP 监听
ss -ulnp # UDP 监听
netstat -tlnp
# 查看所有连接
ss -tanp
netstat -anp
# 查看特定端口
ss -tlnp | grep :80
lsof -i :80
# 连接统计
ss -s
netstat -s
Packet Capture Analysis
# tcpdump 基础
tcpdump -i eth0
tcpdump -i any port 80
tcpdump -i eth0 host 192.168.1.1
tcpdump -i eth0 -w capture.pcap
# 常用过滤
tcpdump -i eth0 'tcp port 80'
tcpdump -i eth0 'host 10.0.0.1 and port 443'
tcpdump -i eth0 'tcp[tcpflags] & tcp-syn != 0'
# 读取抓包文件
tcpdump -r capture.pcap
tcpdump -r capture.pcap -A # 显示 ASCII
Common Scenarios
Scenario 1: Troubleshooting Network Unreachability
# 1. 检查本地网络
ip addr
ip route
# 2. 测试网关连通性
ping gateway_ip
# 3. 测试目标连通性
ping target_ip
traceroute target_ip
# 4. 检查 DNS
nslookup target_hostname
Scenario 2: Troubleshooting Port Unreachability
# 1. 检查服务是否监听
ss -tlnp | grep :port
# 2. 检查防火墙
iptables -L -n
firewall-cmd --list-all
# 3. 从远程测试
nc -zv target_ip port
Scenario 3: Troubleshooting Connection Timeouts
# 1. 检查网络延迟
ping -c 10 target
# 2. 检查路由
mtr target
# 3. 抓包分析
tcpdump -i eth0 host target -w debug.pcap
Troubleshooting
| Issue | Troubleshooting Method |
|---|---|
| Network unreachable | ping, traceroute, check routing |
| DNS resolution failure | nslookup, dig, check /etc/resolv.conf |
| Port unreachable | ss -tlnp, check firewall |
| Connection timeout | mtr, tcpdump packet capture analysis |
| Connection refused | Check service status, port listening |