linux系统怎么测试网速
linux系统怎么测试网速详细介绍
在 Linux 系统中测试网速可以通过多种工具实现,涵盖命令行和图形界面。以下是具体方法及详细操作指南:
一、命令行工具:快速测试网络速度
1.
Speedtest-CLI(推荐)
- 功能:基于 Speedtest.net 服务器,提供全球节点测试,直接输出下载 / 上传速度和延迟。
- 安装:bash
speedtest-cli
dnf speedtest-cli
pip3 speedtest-cli
- 使用:bash
speedtestspeedtest
speedtest
- 示例输出:plaintext
Retrieving speedtest.net configuration...Testing from Tencent cloud computing (140.143.139.14)...
Selecting best server based on ping...
Hosted by Henan CMCC 5G (Zhengzhou) (9.69 km): 28.288 ms
Download: 56.20 Mbit/s
Upload: 1.03 Mbit/s
2.
Fast-CLI(轻量级)
- 功能:基于 Netflix 的 fast.com 服务,专注于下载速度测试,支持上传测试。
- 安装:bash
https://deb.nodesource.com/setup_15.x -
nodejs
fast-cli
- 使用:bash
fastfast
fast result.json
- 示例输出:plaintext
93 Mbps ↓81 Mbps ↓ / 8.3 Mbps ↑ # 带上传测试
3.
iperf3(专业网络测试)
- 功能:测试本地网络或跨设备的带宽、延迟、丢包率,支持 TCP/UDP 协议。
- 安装:bash
iperf3dnf iperf3
- 使用:
- 服务器端(A 设备):bash
iperf3iperf3
- 客户端(B 设备):bash
iperf3 .1.100iperf3 .1.100
iperf3 .1.100
- 服务器端(A 设备):bash
- 示例输出:plaintext
[ ID] Interval Transfer Bandwidth[ 5] 0.00-10.00 sec 1.13 GBytes 966 Mbits/sec sender
[ 5] 0.00-10.00 sec 1.13 GBytes 966 Mbits/sec receiver
4.
wget/curl(粗略估算)
- 功能:通过下载已知大小的文件计算速度,适合临时测试。
- 示例:bash
--show-progress https://example.com/large-file.iso
/dev/null https://example.com/large-file.iso
- 结果解释:plaintext
10.23 833335 # 总时间 10.23 秒,下载速度 833335 字节/秒(约 6.4 Mbps)
二、实时监控工具:分析流量分布
1.
iftop
- 功能:实时显示网络接口的带宽使用情况,按主机或端口排序。
- 安装:bash
iftopdnf iftop
- 使用:bash
iftop eth0 - 交互命令:
t:切换总字节数显示。p:切换端口 / 主机显示。b:切换流量方向。
2.
nload
- 功能:分开展示入站和出站流量,支持图形化界面。
- 安装:bash
nloaddnf nload
- 使用:bash
nload
三、上传速度测试:文件传输工具
1.
scp
- 功能:通过安全复制大文件估算上传速度。
- 示例:bash
large-file.iso user@remote-server:/path
- 结果解释:plaintext
real 0m15.368s # 总耗时100MB/s # 实时速度(输出中显示)
2.
rsync
- 功能:增量传输文件,适合长时间或大文件测试。
- 示例:bash
local-dir/ user@remote-server:/path
- 结果解释:plaintext
sent 131 bytes received 229,426 bytes 41,737.64 bytes/sec # 平均速度
四、专业工具:深度性能分析
1.
netperf
- 功能:测试 TCP/UDP 吞吐量、延迟等,适合企业级网络。
- 安装:bash
netperfdnf netperf
- 使用:
- 服务器端:bash
netserver - 客户端:bash
netperf .1.100 TCP_STREAM
- 服务器端:bash
五、图形界面工具:直观监控
1.
GNOME 网络监控
- 功能:在系统托盘中显示实时上传 / 下载速度。
- 安装:bash
gnome-shell-extension-netspeed - 启用:通过 Gnome Tweaks 启用扩展。
2.
KDE 系统监视器
- 功能:显示网络流量图表,支持历史数据查看。
- 启动:bash
ksysguard
六、注意事项
- 单位转换:
- Mbps(兆比特 / 秒):1 Mbps = 125 KB/s(例如:100 Mbps = 12.5 MB/s)。
- MB/s(兆字节 / 秒):1 MB/s = 8 Mbps。
- 环境影响:
- 测试时关闭其他网络应用,避免干扰。
- 多次测试取平均值,排除临时波动。
- 防火墙设置:
- 使用 iperf3 或 netperf 时,需开放对应端口(如 5201/tcp):bash
ufw allow /tcp912 ufw allow /tcp
- 使用 iperf3 或 netperf 时,需开放对应端口(如 5201/tcp):bash
通过以上工具,你可以全面测试 Linux 系统的网络速度,从简单的全局测速到专业的性能分析,满足不同场景需求。