在Ubuntu系统中,网络管理是日常运维和故障排查的核心技能。
ping
- 测试网络连通性
ping google.com # 持续测试
ping -c 4 google.com # 发送4个包后停止
traceroute
/ tracepath
- 追踪数据包路径
traceroute github.com
tracepath github.com # 无需root权限
mtr
- 实时网络质量分析(结合ping+traceroute)
mtr -rw github.com # 生成报告并退出
ip
- 全能网络工具(取代过时的ifconfig
)
ip addr show # 查看所有接口IP
ip route # 显示路由表
ip -s link # 查看接口统计信息
nmcli
- NetworkManager命令行控制
nmcli device status # 查看设备状态
nmcli connection show # 显示所有连接
ss
- 查看套接字信息(替代netstat
)
ss -tuln # 查看所有监听端口
ss -s # 统计摘要
nmap
- 端口扫描神器
sudo nmap -sS 192.168.1.0/24 # 扫描局域网
sudo nmap -p 80,443 google.com # 指定端口扫描
dig
- DNS查询工具
dig google.com A # 查询A记录
dig +short google.com # 简化输出
host
- 简易DNS查询
host github.com
host 140.82.121.3 # 反向DNS解析
curl
- 数据传输工具
curl -I https://ubuntu.com # 仅显示HTTP头
curl -o file.zip http://example.com/file.zip # 下载文件
wget
- 文件下载
wget -c http://example.com/bigfile.iso # 断点续传
telnet
/ nc
- 端口连通性测试
telnet google.com 80
nc -zv google.com 443 # 快速测试端口
tcpdump
- 网络抓包分析
sudo tcpdump -i eth0 port 80 # 捕获eth0接口80端口流量
sudo tcpdump -w capture.pcap # 保存为pcap文件
iptables
- 防火墙配置
sudo iptables -L # 列出规则
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT # 允许SSH
ethtool
- 网卡诊断
sudo ethtool eth0 # 查看网卡信息
sudo ethtool -s eth0 speed 1000 duplex full # 强制千兆全双工
arp
- ARP缓存管理
arp -n # 显示ARP表(禁用反向解析)
route
- 路由表管理(旧版,建议用ip route
)
route -n # 显示数字格式路由表
hostname
- 主机名操作
hostname -I # 显示所有IP地址
whois
- 域名注册信息查询
whois ubuntu.com
ssh
- 远程登录
ssh user@server -p 2222 # 指定端口连接
ping -c 3 google.com && curl -I https://google.com
sudo
man ip # 查看命令手册
ip --help # 快速帮助
提示:网络故障排查标准流程:
ping
网关 → 2.ping
外部DNS → 3.nslookup
域名解析 → 4.traceroute
路径追踪
掌握这些命令后,你将能高效处理90%的Ubuntu网络问题。建议在测试环境中实操体验,逐步构建自己的网络工具箱!