温馨提示×

linux ifconfig怎么看流量

小樊
44
2026-10-07 22:02:18
栏目: 智能运维

在 Linux 里,ifconfig 本身可以看累计流量,但不能看实时速率。下面分情况说明。


一、用 ifconfig 看累计流量(接收/发送字节数)

执行:

ifconfig

或指定网卡(如 eth0):

ifconfig eth0

示例输出(重点看这两行):

RX packets 123456  bytes 987654321 (987.6 MB)
TX packets 654321  bytes 123456789 (123.4 MB)

含义:

  • RX bytes:接收总流量(下载)
  • TX bytes:发送总流量(上传)

⚠️ 注意:

  • 这是从开机到现在累计的值
  • 重启网卡或系统会清零

二、ifconfig 看“实时流量”?不行

ifconfig 没有实时速率显示
要看实时流量,需要用其他工具。


三、看实时流量(推荐工具)

1️⃣ ip 命令(替代 ifconfig)

ip -s link

或指定网卡:

ip -s link show eth0

2️⃣ 最常用:iftop(实时速率)

iftop -i eth0
  • 实时显示每个连接的上下行速率
  • 安装:
yum install iftop      # CentOS
apt install iftop      # Ubuntu

3️⃣ nload(整体网卡流量)

nload eth0
  • 简单直观,看总入/出速率

4️⃣ sar(历史+实时)

sar -n DEV 1
  • 每秒刷新网卡流量

四、简单计算实时速率(不用工具)

ifconfig eth0 | grep bytes
sleep 1
ifconfig eth0 | grep bytes

两次差值 ÷ 1 秒 ≈ 速率


总结

需求 工具
累计流量 ifconfig / ip
实时速率 iftop / nload
历史统计 sar

如果你是服务器排查流量异常,我可以给你一条最直接命令。

0 踩