在 Linux 里,ifconfig 本身不能实时测流量,但它可以查看网络接口的流量统计信息(累计值),你可以据此手动计算流量。
执行:
ifconfig eth0
(把 eth0 换成你的网卡名,如 ens33、wlan0)
你会看到类似:
RX packets 123456 bytes 987654321 (987.6 MB)
TX packets 654321 bytes 123456789 (123.4 MB)
含义:
1️⃣ 记录开始流量:
ifconfig eth0 | grep bytes
2️⃣ 等一段时间(比如 10 秒)
3️⃣ 再记录一次:
ifconfig eth0 | grep bytes
4️⃣ 手动相减:
流量 = 后 bytes - 前 bytes
速率 = 流量 / 时间
示例:
ifconfig 已逐渐废弃,建议用这些:
ip 命令(替代 ifconfig)ip -s link show eth0
watch -n 1 "ifconfig eth0 | grep bytes"
或更好用:
iftop
nload
vnstat
安装示例(Debian/Ubuntu):
sudo apt install iftop nload vnstat
✅ ifconfig 能看累计流量
❌ 不能直接测实时速率
✅ 用「前后差值」可算速率
✅ 推荐 iftop / nload / vnstat
如果你告诉我:
我可以给你更精确的方案。