在 Linux 里 ifconfig 本身不能直接测网速(带宽/速率),它只能查看网络接口状态和累计流量。不过可以借助 ifconfig 的流量数据来“手动估算”网速。
ifconfig eth0
(把 eth0 换成你的网卡名,如 ens33、wlan0)
关注这两行:
RX packets bytes
TX packets bytes
RX bytes:接收字节数TX bytes:发送字节数第一次:
ifconfig eth0 | grep "RX bytes"
等 10 秒
第二次:
ifconfig eth0 | grep "RX bytes"
网速 = (第二次字节 - 第一次字节) / 时间(秒)
例如:
ip 命令(ifconfig 的替代)ip -s link show eth0
iftop(实时流量)sudo iftop -i eth0
nloadnload eth0
sar(系统级)sar -n DEV 1
speedtest-cli
或
curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3
| 方法 | 是否能测速 | 说明 |
|---|---|---|
| ifconfig | ❌ 间接 | 只能看流量 |
| ip -s | ❌ 间接 | 类似 ifconfig |
| iftop / nload | ✅ 实时 | 推荐 |
| speedtest | ✅ 真测速 | 最准确 |
如果你愿意,可以告诉我:
我可以给你最合适的命令。