CentOS 8 iperf3 安装与命令参数详解
在 CentOS 8 上在线/离线安装 iperf3 3.5 并逐参数实测客户端与服务端命令输入与回显,涵盖 -c/-P/-u/-b/-R/-t/-i/-w/-l/-p/-O 与 -J JSON 输出。
CentOS 8 iperf3 安装与命令参数详解
目标:在 CentOS 8 上安装 iperf3 3.5,并逐参数实测客户端/服务端带宽测试命令的输入与回显,涵盖在线 dnf / 离线 rpm 两种安装方式,以及
-c、-P、-u、-b、-R、-t/-i、-w、-l、-p、-O、-J等参数。本文命令与输出均为 CentOS 8(iperf3 3.5-6.el8,RPM 包iperf3-3.5-6.el8.x86_64)双机实测回显。
一、环境信息
- 操作系统:CentOS 8(8.4.2105)
- iperf3 版本:3.5(RPM 包
iperf3-3.5-6.el8.x86_64,依赖lksctp-tools-1.0.18-3.el8.x86_64) - 本机(测试客户端):eth0,IP
172.27.0.5,同属172.27.0.0/16内网 - 对端主机(测试服务端):IP
172.27.0.4,监听 5201 端口 - 双向 TCP/UDP 均在同一内网段,路径无 NAT,实测吞吐约 30 Gbits/sec
- 说明:CentOS 8 已于 2021 年底 EOL,官方镜像仓库下线后需将源切换为可用镜像(见 3.1 说明)
二、工具概述
iperf3 是新一代的带宽/吞吐量测试工具,在单条 TCP/UDP 连接(默认)或多条并行连接上以固定间隔周期性上报吞吐、重传、拥塞窗口等指标,广泛用于验证网卡、交换机、链路带宽与 QoS 限速配置。它采用「服务端 + 客户端」主从模型:服务端 -s 监听端口等待连接,客户端 -c <host> 发起连接并发送/接收数据。支持 TCP、UDP、SCTP,可指定时长(-t)、间隔(-i)、限速(-b)、并行流(-P)、反向(-R)以及 JSON 结构化输出(-J)。本文针对 CentOS 8 上的 3.5 实测,输出结构与 Ubuntu 22.04 的 3.9 基本一致(本文实测的 el8 包为 3.5,无 --dscp、--extra-data、--repeating-payload 等 3.9 新增项)。
三、安装
3.1 在线安装(dnf)
sudo dnf install -y iperf3
# 或
sudo yum install -y iperf3
⚠️ CentOS 8 已于 2021 年底 EOL,默认源(mirror.centos.org / mirrorlist.centos.org)已不可用。若
dnf install报Could not resolve host: mirrorlist.centos.org或Status code: 403,先把源切换为可用镜像(如阿里云):sed -i 's|^mirrorlist=|#mirrorlist=|g' /etc/yum.repos.d/CentOS-Linux-*.repo sed -i 's|^#baseurl=http://mirror.centos.org/$contentdir/$releasever/|baseurl=https://mirrors.aliyun.com/centos/8/|g' /etc/yum.repos.d/CentOS-Linux-BaseOS.repo /etc/yum.repos.d/CentOS-Linux-AppStream.repo /etc/yum.repos.d/CentOS-Linux-Extras.repo sudo dnf makecache切换后
dnf makecache正常回显Metadata cache created.即可继续安装。
安装后验证(包管理视角):
rpm -q iperf3
iperf3-3.5-6.el8.x86_64
版本号(二进制视角,-v):
iperf3 -v
iperf 3.5 (cJSON 1.5.2)
Linux 172.27.0.5 6.8.0-138-generic #138~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 7 13:43:15 UTC x86_64
Optional features available: CPU affinity setting, IPv6 flow label, SCTP, TCP congestion control algorithm setting, sendfile / zerocopy, socket pacing, authentication
3.2 离线安装(rpm 包)
在可联网的 CentOS 8 机器上下载 rpm(dnf download 由 dnf-plugins-core 提供):
mkdir -p /opt/data/iperf3
cd /opt/data/iperf3
sudo dnf install -y dnf-plugins-core
dnf download iperf3 lksctp-tools
(1/4): iperf3-3.5-6.el8.x86_64.rpm 287 kB/s | 100 kB 00:00
(2/4): lksctp-tools-1.0.18-3.el8.i686.rpm 238 kB/s | 102 kB 00:00
(3/4): iperf3-3.5-6.el8.i686.rpm 215 kB/s | 107 kB 00:00
(4/4): lksctp-tools-1.0.18-3.el8.x86_64.rpm 395 kB/s | 100 kB 00:00
💡
dnf download默认会把当前架构与兼容架构(x86_64 与 i686)的包都下载下来;离线机器为 x86_64 时只需安装 x86_64 的两个包。
拷贝到离线机器后本地安装(自动处理依赖若已齐全):
rpm -ivh /opt/data/iperf3/iperf3-3.5-6.el8.x86_64.rpm /opt/data/iperf3/lksctp-tools-1.0.18-3.el8.x86_64.rpm
安装后验证:
iperf3 -v | head -1
iperf 3.5 (cJSON 1.5.2)
⚠️ 若报依赖缺失,用
rpm -ivh依次安装依赖或用dnf install ./iperf3-3.5-6.el8.x86_64.rpm让 dnf 自动解析。
四、命令实测
4.1 服务端启动 —— iperf3 -s
用途:在服务端监听 5201 端口等待客户端接入。前台运行时会打印「Server listening」横幅,并在每次接入后回报传输数据。
iperf3 -s
服务端前台真实回显(本机 172.27.0.4,接收来自客户端 172.27.0.5 的一次 5 秒 TCP 测试):
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 172.27.0.5, port 47626
[ 5] local 172.27.0.4 port 5201 connected to 172.27.0.5 port 47638
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 3.47 GBytes 29.8 Gbits/sec
[ 5] 1.00-2.00 sec 3.63 GBytes 31.1 Gbits/sec
[ 5] 2.00-3.00 sec 3.22 GBytes 27.7 Gbits/sec
[ 5] 3.00-4.00 sec 3.48 GBytes 29.9 Gbits/sec
[ 5] 4.00-5.00 sec 3.64 GBytes 31.3 Gbits/sec
[ 5] 5.00-5.04 sec 133 MBytes 27.8 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate
[ 5] 0.00-5.04 sec 17.6 GBytes 29.9 Gbits/sec receiver
后台守护运行(-s -D 以守护进程方式启动,脱离终端常驻):
iperf3 -s -D
💡
-D(daemon)使服务端后台常驻,适合长期提供服务;结合-1(one-off)可实现「处理一次连接后自动退出」的一次性服务。
4.2 客户端基础 TCP 测试 —— iperf3 -c 172.27.0.4
用途:客户端向服务端 172.27.0.4:5201 发起默认 10 秒的 TCP 上行测速。
参数说明:-c <host> 指定目标服务端;默认协议为 TCP、时长 10 秒(-t 默认值)、间隔 1 秒刷新一次(-i 默认 1)。
iperf3 -c 172.27.0.4 -t 5
Connecting to host 172.27.0.4, port 5201
[ 5] local 172.27.0.5 port 47638 connected to 172.27.0.4 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 3.61 GBytes 31.0 Gbits/sec 0 2.52 MBytes
[ 5] 1.00-2.00 sec 3.60 GBytes 30.9 Gbits/sec 0 3.22 MBytes
[ 5] 2.00-3.00 sec 3.22 GBytes 27.7 Gbits/sec 1 3.23 MBytes
[ 5] 3.00-4.00 sec 3.49 GBytes 30.0 Gbits/sec 2 3.28 MBytes
[ 5] 4.00-5.00 sec 3.63 GBytes 31.2 Gbits/sec 1 3.28 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-5.00 sec 17.6 GBytes 30.2 Gbits/sec 4 sender
[ 5] 0.00-5.04 sec 17.6 GBytes 29.9 Gbits/sec receiver
iperf Done.
解读:首行 Connecting to host 172.27.0.4, port 5201 明确连接目标与端口;第二行 [ 5] local 172.27.0.5 port 47638 connected to 172.27.0.4 port 5201 为分配的连接 socket 信息(客户端源端口 47638)。中间每行是 1 秒间隔的瞬时吞吐,Retr 为重传次数、Cwnd 为拥塞窗口。底部汇总行 0.00-5.00 为整个测试期间的平均值:发送方向 17.6 GBytes / 30.2 Gbits/sec,接收方向 17.6 GBytes / 29.9 Gbits/sec。iperf Done. 表示测试正常结束(返回码 0)。
4.3 并行数据流 —— iperf3 -c 172.27.0.4 -P 3
用途:用 3 条并行 TCP 连接同时测速,模拟多连接/多核并发场景,检验单条连接之外的聚合带宽上限。
参数说明:-P <n> 指定并行流数(默认 1)。
iperf3 -c 172.27.0.4 -P 3 -t 3
Connecting to host 172.27.0.4, port 5201
[ 5] local 172.27.0.5 port 47662 connected to 172.27.0.4 port 5201
[ 7] local 172.27.0.5 port 47670 connected to 172.27.0.4 port 5201
[ 9] local 172.27.0.5 port 47680 connected to 172.27.0.4 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 1.45 GBytes 12.5 Gbits/sec 0 2.02 MBytes
[ 7] 0.00-1.00 sec 1.44 GBytes 12.4 Gbits/sec 1 523 KBytes
[ 9] 0.00-1.00 sec 1.45 GBytes 12.5 Gbits/sec 2 799 KBytes
[SUM] 0.00-1.00 sec 4.35 GBytes 37.4 Gbits/sec 3
- - - - - - - - - - - - - - - - - - - - - - - - -
[ 5] 1.00-2.00 sec 1.29 GBytes 11.1 Gbits/sec 0 3.83 MBytes
[ 7] 1.00-2.00 sec 1.27 GBytes 10.9 Gbits/sec 178 590 KBytes
[ 9] 1.00-2.00 sec 1.28 GBytes 11.0 Gbits/sec 423 690 KBytes
[SUM] 1.00-2.00 sec 3.84 GBytes 32.9 Gbits/sec 601
- - - - - - - - - - - - - - - - - - - - - - - - -
[ 5] 2.00-3.00 sec 1.44 GBytes 12.4 Gbits/sec 0 3.83 MBytes
[ 7] 2.00-3.00 sec 1.44 GBytes 12.3 Gbits/sec 2 691 KBytes
[ 9] 2.00-3.00 sec 1.44 GBytes 12.4 Gbits/sec 115 650 KBytes
[SUM] 2.00-3.00 sec 4.32 GBytes 37.1 Gbits/sec 117
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-3.00 sec 4.19 GBytes 12.0 Gbits/sec 0 sender
[ 5] 0.00-3.04 sec 4.19 GBytes 11.8 Gbits/sec receiver
[ 7] 0.00-3.00 sec 4.15 GBytes 11.9 Gbits/sec 181 sender
[ 7] 0.00-3.04 sec 4.15 GBytes 11.7 Gbits/sec receiver
[ 9] 0.00-3.00 sec 4.17 GBytes 11.9 Gbits/sec 540 sender
[ 9] 0.00-3.04 sec 4.17 GBytes 11.8 Gbits/sec receiver
[SUM] 0.00-3.00 sec 12.5 GBytes 35.8 Gbits/sec 721 sender
[SUM] 0.00-3.04 sec 12.5 GBytes 35.3 Gbits/sec receiver
iperf Done.
解读:3 条连接各分配一个 [ 5]/[ 7]/[ 9] 标识行,[SUM] 为三条流的聚合行。每条流约 11~12 Gbits/sec,聚合 [SUM] 12.5 GBytes / 35.8 Gbits/sec,说明多流可突破单流的吞吐上限、逼近链路总带宽。
4.4 UDP 模式 —— iperf3 -c 172.27.0.4 -u -b 200M
用途:UDP 测速重点评估抖动(Jitter)、丢包率,适合模拟语音/视频等实时流量。
参数说明:-u 改用 UDP;-b 200M 指定目标发送速率(UDP 默认 1 Mbit/sec,必须显式给定额度)。
iperf3 -c 172.27.0.4 -u -b 200M -t 3
Connecting to host 172.27.0.4, port 5201
[ 5] local 172.27.0.5 port 35504 connected to 172.27.0.4 port 5201
[ ID] Interval Transfer Bitrate Total Datagrams
[ 5] 0.00-1.00 sec 23.8 MBytes 200 Mbits/sec 17263
[ 5] 1.00-2.00 sec 23.8 MBytes 200 Mbits/sec 17254
[ 5] 2.00-3.00 sec 23.8 MBytes 200 Mbits/sec 17265
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
[ 5] 0.00-3.00 sec 71.5 MBytes 200 Mbits/sec 0.000 ms 0/51782 (0%) sender
[ 5] 0.00-3.04 sec 71.5 MBytes 197 Mbits/sec 0.005 ms 6/51782 (0.012%) receiver
iperf Done.
解读:UDP 模式下每行多出 Total Datagrams(数据报数),汇总行给出 Jitter(抖动)和 Lost/Total Datagrams(丢包/总报文)。本例发送 200 Mbits/sec、共 51782 个报文,接收端抖动 0.005 ms、丢包 6/51782(0.012%),丢包率极低,链路健康。
4.5 限速测试 —— iperf3 -c 172.27.0.4 -b 1G
用途:TCP 模式下用 -b 限速,验证链路/QoS 对限速额度的响应与丢包重传表现。
参数说明:-b <rate> 在 TCP 下限制发送速率,在 UDP 下为目标发送速率;可带 K/M/G 后缀。
iperf3 -c 172.27.0.4 -b 1G -t 3
Connecting to host 172.27.0.4, port 5201
[ 5] local 172.27.0.5 port 41246 connected to 172.27.0.4 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 119 MBytes 999 Mbits/sec 0 331 KBytes
[ 5] 1.00-2.00 sec 119 MBytes 1.00 Gbits/sec 0 403 KBytes
[ 5] 2.00-3.00 sec 119 MBytes 1.00 Gbits/sec 0 423 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-3.00 sec 358 MBytes 1000 Mbits/sec 0 sender
[ 5] 0.00-3.04 sec 358 MBytes 987 Mbits/sec receiver
iperf Done.
解读:-b 1G 将发送速率稳定压制在 999~1000 Mbits/sec,Retr 为 0,说明限速生效且未引发丢包重传。对比 4.2 无限制时 30.2 Gbits/sec,-b 精确控制了发送速率——常用于验证带宽整形/限速策略。
4.6 反向模式 —— iperf3 -c 172.27.0.4 -R
用途:缺省为客户端 → 服务端发送;-R 反转为「服务端发送、客户端接收」,用于测试下行带宽。
参数说明:-R 使服务端变成发送方。
iperf3 -c 172.27.0.4 -R -t 4 -i 1
Connecting to host 172.27.0.4, port 5201
Reverse mode, remote host 172.27.0.4 is sending
[ 5] local 172.27.0.5 port 50038 connected to 172.27.0.4 port 5201
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 3.56 GBytes 30.6 Gbits/sec
[ 5] 1.00-2.00 sec 3.19 GBytes 27.4 Gbits/sec
[ 5] 2.00-3.00 sec 3.31 GBytes 28.5 Gbits/sec
[ 5] 3.00-4.00 sec 3.82 GBytes 32.8 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-4.04 sec 13.9 GBytes 29.5 Gbits/sec 3 sender
[ 5] 0.00-4.00 sec 13.9 GBytes 29.8 Gbits/sec receiver
iperf Done.
解读:输出首行 Reverse mode, remote host 172.27.0.4 is sending 提示反向模式;本次下行平均 29.5 Gbits/sec(sender 指服务端)。-R 与 -P、-b 等常组合使用。
4.7 时长与间隔 —— iperf3 -c 172.27.0.4 -t 3 -i 1
用途:-t 控制测试秒数(默认 10),-i 控制周期报告间隔秒数(默认 1),用更短时长快速完成功能验证。
参数说明:-t <sec> 测试时长;-i <sec> 周期上报间隔。
iperf3 -c 172.27.0.4 -t 3 -i 1
Connecting to host 172.27.0.4, port 5201
[ 5] local 172.27.0.5 port 38754 connected to 172.27.0.4 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 3.72 GBytes 32.0 Gbits/sec 1 1.46 MBytes
[ 5] 1.00-2.00 sec 3.70 GBytes 31.7 Gbits/sec 1 1.46 MBytes
[ 5] 2.00-3.00 sec 3.67 GBytes 31.5 Gbits/sec 3 1.46 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-3.00 sec 11.1 GBytes 31.7 Gbits/sec 5 sender
[ 5] 0.00-3.04 sec 11.1 GBytes 31.3 Gbits/sec receiver
iperf Done.
解读:-t 3 -i 1 只跑 3 秒、每 1 秒出一次报告,运行更快;脚本循环采集时可用更小的 -i 提高采样密度。也支持用 -n <bytes>(按字节)或 -k <count>(按报文数)替代 -t 控制测试量。
4.8 接收/发送窗口 —— iperf3 -c 172.27.0.4 -w 1M(含报错处理)
用途:-w 设置 socket 发送/接收缓冲区(窗口)大小,用于长肥管道(高带宽高延迟)场景下提升吞吐。
参数说明:-w <size> 设定窗口/套接字缓冲区大小,可带 K/M/G 后缀。
实测回显(-w 1M 报错):
iperf3 -c 172.27.0.4 -w 1M -t 3
iperf3: error - socket buffer size not set correctly
Connecting to host 172.27.0.4, port 5201
解读与解决:报 socket buffer size not set correctly 说明请求的 -w 值超过了系统套接字缓冲区上限(Linux 默认 net.core.wmem_max/net.core.rmem_max 约 212992 字节)。改用不超过上限的取值即可正常执行,例如 -w 200K:
iperf3 -c 172.27.0.4 -w 200K -t 2
Connecting to host 172.27.0.4, port 5201
[ 5] local 172.27.0.5 port 41142 connected to 172.27.0.4 port 5201
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-2.00 sec 6.33 GBytes 27.2 Gbits/sec 12 sender
[ 5] 0.00-2.04 sec 6.33 GBytes 26.9 Gbits/sec receiver
iperf Done.
如需更大的 -w,需先调高内核参数(真实服务器上执行,重启后仍生效可持久化到 /etc/sysctl.conf):
sudo sysctl -w net.core.wmem_max=1048576 net.core.rmem_max=1048576
4.9 缓冲区长度 —— iperf3 -c 172.27.0.4 -l 64K
用途:-l 指定单次读写的缓冲区/报文长度。TCP 默认 128 KB;调整后可观察不同报文分节对吞吐的影响。
参数说明:-l <len> 设置读写缓冲区长度。
iperf3 -c 172.27.0.4 -l 64K -t 3
Connecting to host 172.27.0.4, port 5201
[ 5] local 172.27.0.5 port 48260 connected to 172.27.0.4 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 3.06 GBytes 26.3 Gbits/sec 3 3.23 MBytes
[ 5] 1.00-2.00 sec 3.26 GBytes 28.0 Gbits/sec 50 3.23 MBytes
[ 5] 2.00-3.00 sec 3.19 GBytes 27.4 Gbits/sec 0 3.23 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-3.00 sec 9.52 GBytes 27.3 Gbits/sec 53 sender
[ 5] 0.00-3.04 sec 9.52 GBytes 26.9 Gbits/sec receiver
iperf Done.
解读:改用 64 KB 缓冲后平均 27.3 Gbits/sec,与默认 128 KB 的 31.7 Gbits/sec 略有下降,说明该场景下减小缓冲长度对吞吐影响有限、稍偏负向。
4.10 自定义端口 —— iperf3 -c 172.27.0.4 -p 5202
用途:默认服务端监听/客户端连接 5201;-p 可指定其他端口,便于多实例、多场景并存。
参数说明:客户端 -p <port> 与 -c 连目标端口;服务端需先用 iperf3 -s -p 5202 在同端口监听。
服务端用 5202 端口监听:
iperf3 -s -p 5202
客户端连接 172.27.0.4:5202:
iperf3 -c 172.27.0.4 -p 5202 -t 3
Connecting to host 172.27.0.4, port 5202
[ 5] local 172.27.0.5 port 39032 connected to 172.27.0.4 port 5202
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 3.75 GBytes 32.2 Gbits/sec 0 3.83 MBytes
[ 5] 1.00-2.00 sec 3.75 GBytes 32.2 Gbits/sec 1 3.83 MBytes
[ 5] 2.00-3.00 sec 3.12 GBytes 26.8 Gbits/sec 2 2.74 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-3.00 sec 10.6 GBytes 30.4 Gbits/sec 3 sender
[ 5] 0.00-3.04 sec 10.6 GBytes 30.0 Gbits/sec receiver
iperf Done.
解读:首行 port 5202 确认连到自定义端口;其余输出结构与 5201 一致。注意同一端口只能被一个服务端实例占用。
4.11 省略起始段 —— iperf3 -c 172.27.0.4 -O 1
用途:-O N 在统计中省略前 N 秒,避开枚举/建链/拥塞窗口爬升等「预热期」,让平均吞吐更能体现稳定状态。
参数说明:-O <N> 报告时省略前 N 秒(不影响总时长)。
iperf3 -c 172.27.0.4 -O 1 -t 4 -i 1
Connecting to host 172.27.0.4, port 5201
[ 5] local 172.27.0.5 port 33306 connected to 172.27.0.4 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 2.87 GBytes 24.7 Gbits/sec 0 3.83 MBytes (omitted)
[ 5] 0.00-1.00 sec 3.10 GBytes 26.6 Gbits/sec 0 3.83 MBytes
[ 5] 1.00-2.00 sec 2.90 GBytes 24.9 Gbits/sec 0 3.83 MBytes
[ 5] 2.00-3.00 sec 3.15 GBytes 27.0 Gbits/sec 0 3.83 MBytes
[ 5] 3.00-4.00 sec 3.37 GBytes 28.9 Gbits/sec 1 3.83 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-4.00 sec 12.5 GBytes 26.9 Gbits/sec 1 sender
[ 5] 0.00-4.04 sec 12.6 GBytes 26.9 Gbits/sec receiver
iperf Done.
解读:第 1 秒的间隔行被标记为 (omitted)(仅显示、不参与平均),其余行正常上报。
4.12 JSON 结构化输出 —— iperf3 -c 172.27.0.4 -J
用途:-J 以 JSON 输出完整结果,机器可解析,方便脚本/监控系统消费;--logfile <file> 可将日志写入文件,配合 --forceflush 每次间隔实时落盘。
参数说明:-J 输出 JSON。
iperf3 -c 172.27.0.4 -t 2 -i 1 -J
{
"start": {
"connected": [{
"socket": 5,
"local_host": "172.27.0.5",
"local_port": 40026,
"remote_host": "172.27.0.4",
"remote_port": 5201
}],
"version": "iperf 3.5",
"system_info": "Linux 172.27.0.5 6.8.0-138-generic #138~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 7 13:43:15 UTC x86_64",
"timestamp": {
"time": "Fri, 09 Oct 2026 04:36:44 GMT",
"timesecs": 1791520604
},
"connecting_to": {
"host": "172.27.0.4",
"port": 5201
},
"cookie": "3wvux3zikl2u4kg4wnfp4fxufmnqaavu6x7m",
"tcp_mss_default": 1448,
"sock_bufsize": 0,
"sndbuf_actual": 16384,
"rcvbuf_actual": 131072,
"test_start": {
"protocol": "TCP",
"num_streams": 1,
"blksize": 131072,
"omit": 0,
"duration": 2,
"bytes": 0,
"blocks": 0,
"reverse": 0,
"tos": 0
}
},
"intervals": [{
"streams": [{
"socket": 5,
"start": 0,
"end": 1.0000929832458496,
"seconds": 1.0000929832458496,
"bytes": 3988767120,
"bits_per_second": 31907170127.755646,
"retransmits": 0,
"snd_cwnd": 2896000,
"rtt": 35,
"rttvar": 12,
"pmtu": 1500,
"omitted": false
}],
"sum": {
"start": 0,
"end": 1.0000929832458496,
"seconds": 1.0000929832458496,
"bytes": 3988767120,
"bits_per_second": 31907170127.755646,
"retransmits": 0,
"omitted": false
}
}],
"end": {
"streams": [{
"sender": {
"socket": 5,
"start": 0,
"end": 2.0003659725189209,
"seconds": 2.0003659725189209,
"bytes": 7881605520,
"bits_per_second": 31520654233.386086,
"retransmits": 1,
"max_snd_cwnd": 2896000,
"max_rtt": 120,
"min_rtt": 35,
"mean_rtt": 77
},
"receiver": {
"socket": 5,
"start": 0,
"end": 2.0416278839111328,
"seconds": 2.0003659725189209,
"bytes": 7880950160,
"bits_per_second": 30881044374.854507
}
}],
"sum_sent": {
"start": 0,
"end": 2.0003659725189209,
"seconds": 2.0003659725189209,
"bytes": 7881605520,
"bits_per_second": 31520654233.386086,
"retransmits": 1
},
"sum_received": {
"start": 0,
"end": 2.0416278839111328,
"seconds": 2.0416278839111328,
"bytes": 7880950160,
"bits_per_second": 30881044374.854507
},
"cpu_utilization_percent": {
"host_total": 91.257671067689728,
"host_user": 2.7480951942057037,
"host_system": 88.509575873484025,
"remote_total": 28.219769991213223,
"remote_user": 1.8472749344688251,
"remote_system": 26.372458090914503
},
"sender_tcp_congestion": "cubic",
"receiver_tcp_congestion": "cubic"
}
}
解读:JSON 结构与文本输出一一对应。重点字段:start.connected[](连接两端地址端口)、start.test_start(协议/流数/缓冲块大小/时长)、intervals[](每个周期字节数与 bits_per_second)、end.streams[].sender(发送端汇总,含 max/mean_rtt)、end.sum_sent/sum_received(聚合吞吐)、end.cpu_utilization_percent(本端/对端 CPU 占用)。--get-server-output 可把服务端同样会执行的吞吐测试结果并入客户端 JSON 一并返回。
五、帮助输出
5.1 iperf3 --help(帮助全文,CentOS 8 / el8 3.5 版)
Usage: iperf3 [-s|-c host] [options]
iperf3 [-h|--help] [-v|--version]
Server or Client:
-p, --port # server port to listen on/connect to
-f, --format [kmgtKMGT] format to report: Kbits, Mbits, Gbits, Tbits
-i, --interval # seconds between periodic throughput reports
-F, --file name xmit/recv the specified file
-A, --affinity n/n,m set CPU affinity
-B, --bind <host> bind to the interface associated with the address <host>
-V, --verbose more detailed output
-J, --json output in JSON format
--logfile f send output to a log file
--forceflush force flushing output at every interval
-d, --debug emit debugging output
-v, --version show version information and quit
-h, --help show this message and quit
Server specific:
-s, --server run in server mode
-D, --daemon run the server as a daemon
-I, --pidfile file write PID file
-1, --one-off handle one client connection then exit
--rsa-private-key-path path to the RSA private key used to decrypt
authentication credentials
--authorized-users-path path to the configuration file containing user
credentials
Client specific:
-c, --client <host> run in client mode, connecting to <host>
--sctp use SCTP rather than TCP
-X, --xbind <name> bind SCTP association to links
--nstreams # number of SCTP streams
-u, --udp use UDP rather than TCP
--connect-timeout # timeout for control connection setup (ms)
-b, --bitrate #[KMG][/#] target bitrate in bits/sec (0 for unlimited)
(default 1 Mbit/sec for UDP, unlimited for TCP)
(optional slash and packet count for burst mode)
--pacing-timer #[KMG] set the timing for pacing, in microseconds (default 1000)
--fq-rate #[KMG] enable fair-queuing based socket pacing in
bits/sec (Linux only)
-t, --time # time in seconds to transmit for (default 10 secs)
-n, --bytes #[KMG] number of bytes to transmit (instead of -t)
-k, --blockcount #[KMG] number of blocks (packets) to transmit (instead of -t or -n)
-l, --length #[KMG] length of buffer to read or write
(default 128 KB for TCP, dynamic or 1460 for UDP)
--cport <port> bind to a specific client port (TCP and UDP, default: ephemeral port)
-P, --parallel # number of parallel client streams to run
-R, --reverse run in reverse mode (server sends, client receives)
--bidir run in bidirectional mode.
Client and server send and receive data.
-w, --window #[KMG] set window size / socket buffer size
-C, --congestion <algo> set TCP congestion control algorithm (Linux and FreeBSD only)
-M, --set-mss # set TCP/SCTP maximum segment size (MTU - 40 bytes)
-N, --no-delay set TCP/SCTP no delay, disabling Nagle's Algorithm
-4, --version4 only use IPv4
-6, --version6 only use IPv6
-S, --tos N set the IP type of service, 0-255.
The usual prefixes for octal and hex can be used,
i.e. 52, 064 and 0x34 all specify the same value.
-L, --flowlabel N set the IPv6 flow label (only supported on Linux)
-Z, --zerocopy use a 'zero copy' method of sending data
-O, --omit N omit the first n seconds
-T, --title str prefix every output line with this string
--get-server-output get results from server
--udp-counters-64bit use 64-bit counters in UDP test packets
--username username for authentication
--rsa-public-key-path path to the RSA public key used to encrypt
authentication credentials
[KMG] indicates options that support a K/M/G suffix for kilo-, mega-, or giga-
iperf3 homepage at: http://software.es.net/iperf/
Report bugs to: https://github.com/esnet/iperf
与 Ubuntu 22.04(3.9)帮助文本的差异:el8 的 3.5 帮助中服务端无 --server-bitrate-limit、--use-pkcs1-padding,客户端无 --dscp、--extra-data、--repeating-payload,且首页 URL 写作 http://software.es.net/iperf/(3.9 为 https://)。其余选项一致。
5.2 版本信息 —— iperf3 -v
iperf 3.5 (cJSON 1.5.2)
Linux 172.27.0.5 6.8.0-138-generic #138~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 7 13:43:15 UTC x86_64
Optional features available: CPU affinity setting, IPv6 flow label, SCTP, TCP congestion control algorithm setting, sendfile / zerocopy, socket pacing, authentication
六、常见问题
6.1 连接被拒 / 无法连接
Q:客户端报 iperf3: error - unable to connect to server: Connection refused?
A:说明目标端口上没有服务端在监听。确认服务端已用 iperf3 -s(或 -p <port> 指定同端口)启动,且 -p、IP 一致;可用 ss -tlnp | grep 5201 在服务端核验监听状态。
6.2 安装时报源不可用
Q:dnf install iperf3 报 Could not resolve host: mirrorlist.centos.org 或 Status code: 403?
A:CentOS 8 已 EOL,官方源下线。按 3.1 的说明把 /etc/yum.repos.d/CentOS-Linux-*.repo 的 mirrorlist 注释掉、baseurl 指向可用镜像(如阿里云 https://mirrors.aliyun.com/centos/8/)后 dnf makecache 再安装即可。
6.3 -w 设置窗口报错
Q:iperf3 -w 1M 报 socket buffer size not set correctly?
A:请求的窗口值超过了系统套接字缓冲区上限(默认 net.core.wmem_max/rmem_max 约 212992)。可改用不超过上限的值(如 -w 200K);确需大窗口先用 sysctl -w net.core.wmem_max=1048576 net.core.rmem_max=1048576 调高内核上限。
6.4 输出吞吐「虚高」
Q:内网测出来几十 Gbps,看起来不真实?
A:iperf3 测到的是路径当前能达到的吞吐。在同一内网段、共享转发路径且无瓶颈时,值偏高属正常;要得到贴近运营商的真实带宽,应在被测链路两端(网卡到网卡、跨交换机)对测,并结合多流 -P、UDP -u、反向 -R 交叉验证。
6.5 UDP 与 TCP 结果差异
Q:UDP 限 200M 很稳,TCP 却飙到 30G?
A:UDP 按 -b 限定的速率主动发包(UDP 默认 1 Mbit),是"先限速再测";TCP 无 -b 时默认不限速(尽力而为),测的是链路能塞满的上限。两者用途不同:UDP 多用于抖动/丢包与实时业务模拟,TCP 用于带宽/吞吐基线。
七、参考链接
- iperf3 官方站点:https://software.es.net/iperf/
- 源码与 Issue:https://github.com/esnet/iperf
- man 手册页:iperf3(1)(
man 1 iperf3) - CentOS 8 软件包:
iperf3-3.5-6.el8.x86_64 - 本文素材来源:CentOS 8 双机实测(iperf3 3.5-6.el8)