温馨提示×

linux ifconfig怎么看网速

小樊
47
2026-10-29 07:09:27
栏目: 智能运维

在 Linux 里 ifconfig 本身不能直接看“实时网速”,它只能看网络接口的统计信息(累计收发字节数)。不过你可以通过对比两次 ifconfig 的数据来算网速。


一、用 ifconfig 看累计流量(间接算网速)

1. 查看网卡信息

ifconfig eth0

(把 eth0 换成你的网卡名,用 ifconfig 或 ip a 看)

示例输出里有:

RX bytes:123456789 (123.4 MB)
TX bytes:987654321 (987.6 MB)
  • RX bytes:接收的总字节数
  • TX bytes:发送的总字节数

2. 算网速(手动方法)

ifconfig eth0 | grep "RX bytes"
sleep 5
ifconfig eth0 | grep "RX bytes"

两次 RX bytes 的差值 ÷ 5 秒 = 平均下载速度

例如:

  • 第一次:100000000
  • 5 秒后:100500000
  • 差值:500000 字节
  • 速度:500000 / 5 = 100000 B/s ≈ 0.95 Mbps

二、更简单:用现成工具看实时网速(推荐)

1. ip 命令(替代 ifconfig)

ip -s link

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

# 安装
yum install iftop     # CentOS
apt install iftop     # Ubuntu

# 使用
iftop -i eth0

或者:

nload
apt install nload
nload eth0

3. 最简单一行命令看速率

watch -n 1 "ifconfig eth0 | grep 'RX bytes'"

总结

  • ✅ ifconfig:只能看累计流量
  • ✅ 实时网速:用 iftop / nload 最方便
  • ✅ 算速度:两次 ifconfig 差值 ÷ 时间

如果你告诉我你的 Linux 发行版(CentOS / Ubuntu 等),我可以给你最合适的命令。

0 踩