在 Linux 里 ifconfig 本身不能直接看“实时网速”,它只能看网络接口的统计信息(累计收发字节数)。不过你可以通过对比两次 ifconfig 的数据来算网速。
ifconfig eth0
(把 eth0 换成你的网卡名,用 ifconfig 或 ip a 看)
示例输出里有:
RX bytes:123456789 (123.4 MB)
TX bytes:987654321 (987.6 MB)
ifconfig eth0 | grep "RX bytes"
sleep 5
ifconfig eth0 | grep "RX bytes"
两次 RX bytes 的差值 ÷ 5 秒 = 平均下载速度
例如:
ip 命令(替代 ifconfig)ip -s link
# 安装
yum install iftop # CentOS
apt install iftop # Ubuntu
# 使用
iftop -i eth0
或者:
nload
apt install nload
nload eth0
watch -n 1 "ifconfig eth0 | grep 'RX bytes'"
ifconfig:只能看累计流量如果你告诉我你的 Linux 发行版(CentOS / Ubuntu 等),我可以给你最合适的命令。