在 Linux 里,ifconfig 本身可以看累计流量,但不能看实时速率。下面分情况说明。
执行:
ifconfig
或指定网卡(如 eth0):
ifconfig eth0
示例输出(重点看这两行):
RX packets 123456 bytes 987654321 (987.6 MB)
TX packets 654321 bytes 123456789 (123.4 MB)
含义:
⚠️ 注意:
ifconfig 没有实时速率显示
要看实时流量,需要用其他工具。
ip -s link
或指定网卡:
ip -s link show eth0
iftop -i eth0
yum install iftop # CentOS
apt install iftop # Ubuntu
nload eth0
sar -n DEV 1
ifconfig eth0 | grep bytes
sleep 1
ifconfig eth0 | grep bytes
两次差值 ÷ 1 秒 ≈ 速率
| 需求 | 工具 |
|---|---|
| 累计流量 | ifconfig / ip |
| 实时速率 | iftop / nload |
| 历史统计 | sar |
如果你是服务器排查流量异常,我可以给你一条最直接命令。