温馨提示×

linux ifconfig如何查流量

小樊
47
2026-10-13 19:50:10
栏目: 智能运维

在 Linux 中,ifconfig 本身可以查看网络接口的流量统计信息,但它不是实时流量监控工具。下面是常用方法:


一、用 ifconfig 查流量(累计值)

ifconfig eth0

或(新系统可能用 ip):

ip -s link show eth0

关键字段说明

RX packets 123456  bytes 987654321
TX packets 654321  bytes 123456789
  • RX:接收(入站)
    • packets:接收包数
    • bytes:接收字节数
  • TX:发送(出站)
    • packets:发送包数
    • bytes:发送字节数

✅ 这些是系统启动以来的累计流量


二、用 ifconfig 看“一段时间内的流量”

方法 1:两次 ifconfig 对比

ifconfig eth0 | grep bytes
sleep 10
ifconfig eth0 | grep bytes

手动计算差值即可。


三、更推荐的实时流量工具(比 ifconfig 好用)

1️⃣ ip 命令(推荐)

ip -s -h link show eth0

2️⃣ watch + ifconfig(每秒刷新)

watch -n 1 "ifconfig eth0 | grep bytes"

3️⃣ 专业流量监控工具

# 实时速率
iftop

# 简单流量统计
nload

# 综合监控
sar -n DEV 1

四、换算成“MB / GB”

echo "987654321 bytes = $((987654321/1024/1024)) MB"

✅ 总结

  • ifconfig:看累计流量
  • watch + ifconfig:看变化趋势
  • iftop / nload / sar:看实时速率

如果你是 测服务器流量、限速、排查异常流量,可以告诉我使用场景,我给你更合适的命令。

0 踩