温馨提示×

linux ifconfig如何测网速

小樊
33
2026-10-13 19:48:12
栏目: 智能运维

在 Linux 里 ifconfig 本身不能直接测网速(带宽/速率),它只能查看网络接口状态和累计流量。不过可以借助 ifconfig 的流量数据来“手动估算”网速。


一、用 ifconfig 估算网速(间接方式)

1. 查看当前流量

ifconfig eth0

(把 eth0 换成你的网卡名,如 ens33、wlan0)

关注这两行:

RX packets  bytes
TX packets  bytes
  • RX bytes:接收字节数
  • TX bytes:发送字节数

2. 记录两次流量,计算速率

第一次:

ifconfig eth0 | grep "RX bytes"

等 10 秒

第二次:

ifconfig eth0 | grep "RX bytes"

3. 计算网速

网速 = (第二次字节 - 第一次字节) / 时间(秒)

例如:

  • 10 秒增加 100MB
  • 100MB = 100 × 1024 × 1024 = 104857600 字节
  • 速度 ≈ 10 MB/s ≈ 80 Mbps

二、更推荐的方式(比 ifconfig 好用)

✅ 1. ip 命令(ifconfig 的替代)

ip -s link show eth0

✅ 2. 实时网速工具(强烈推荐)

iftop(实时流量)

sudo iftop -i eth0

nload

nload eth0

sar(系统级)

sar -n DEV 1

✅ 3. 真正“测速”(像宽带测速)

speedtest-cli

或

curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3

三、总结

方法 是否能测速 说明
ifconfig ❌ 间接 只能看流量
ip -s ❌ 间接 类似 ifconfig
iftop / nload ✅ 实时 推荐
speedtest ✅ 真测速 最准确

如果你愿意,可以告诉我:

  • 你是 服务器 / 桌面 / 容器
  • 想测 内网还是外网
  • 是否允许安装软件

我可以给你最合适的命令。

0 踩