Ubuntu 22.04 iperf3 安装与命令参数详解

在 Ubuntu 22.04 上在线/离线安装 iperf3 3.9 并逐参数实测客户端与服务端命令输入与回显,涵盖 -c/-P/-u/-b/-R/-t/-i/-w/-l/-p/-O 与 -J JSON 输出。

网络测试iperf3压测Linux命令行2026/10/09

Ubuntu 22.04 iperf3 安装与命令参数详解

目标:在 Ubuntu 22.04 上安装 iperf3 3.9,并逐参数实测客户端/服务端带宽测试命令的输入与回显,涵盖在线 apt / 离线 deb 两种安装方式,以及 -c、-P、-u、-b、-R、-t/-i、-w、-l、-p、-O、-J 等参数。本文命令与输出均为 Ubuntu 22.04(iperf3 3.9,Debian 包 3.9-1+deb11u1ubuntu0.1)双机实测回显。

一、环境信息

  • 操作系统:Ubuntu 22.04 LTS
  • iperf3 版本:3.9(包 iperf3 3.9-1+deb11u1ubuntu0.1 amd64,依赖 libiperf0 同版本)
  • 本机(测试客户端):eth0,IP 172.27.0.3,同属 172.27.0.0/16 内网
  • 对端主机(测试服务端):IP 172.27.0.2,监听 5201 端口
  • 双向 TCP/UDP 均在同一内网段,路径无 NAT,实测吞吐约 30~35 Gbits/sec
  • 服务端后台守护进程 PID 文件:/tmp/iperf3.pid

二、工具概述

iperf3 是新一代的带宽/吞吐量测试工具,在单条 TCP/UDP 连接(默认)或多条并行连接上以固定间隔周期性上报吞吐、重传、拥塞窗口等指标,广泛用于验证网卡、交换机、链路带宽与 QoS 限速配置。它采用「服务端 + 客户端」主从模型:服务端 -s 监听端口等待连接,客户端 -c <host> 发起连接并发送/接收数据。支持 TCP、UDP、SCTP,可指定时长(-t)、间隔(-i)、限速(-b)、并行流(-P)、反向(-R)以及 JSON 结构化输出(-J)。本文针对 Ubuntu 22.04 上的 3.9 实测。

三、安装

3.1 在线安装(apt)

sudo apt update
sudo apt install -y iperf3

💡 Ubuntu 22.04 仓库中的 iperf3 依赖 libiperf0,安装时会一并自动安装;运行版本为 iperf 3.9。

安装后验证(包管理视角):

dpkg -l iperf3
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version                Architecture Description
+++-==============-======================-============-==========================================
ii  iperf3         3.9-1+deb11u1ubuntu0.1 amd64        Internet Protocol bandwidth measuring tool

版本号(二进制视角,-v):

iperf3 -v
iperf 3.9 (cJSON 1.7.13)
Linux 172.27.0.3 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 algorithm setting, sendfile / zerocopy, socket pacing, authentication

3.2 离线安装(.deb 包)

在可联网的 Ubuntu 机器上下载 iperf3 及其依赖:

mkdir -p /opt/data/iperf3
cd /opt/data/iperf3
apt download iperf3 libiperf0
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 iperf3 amd64 3.9-1+deb11u1ubuntu0.1 [14.6 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 libiperf0 amd64 3.9-1+deb11u1ubuntu0.1 [82.8 kB]
Fetched 97.4 kB in 1s (67.0 kB/s)

下载得到两个 deb 包:

iperf3_3.9-1+deb11u1ubuntu0.1_amd64.deb
libiperf0_3.9-1+deb11u1ubuntu0.1_amd64.deb

拷贝到离线机器后一键安装:

dpkg -i /opt/data/iperf3/*.deb

安装后验证:

iperf3 -v | head -1
iperf 3.9 (cJSON 1.7.13)

⚠️ 安装过程若提示依赖缺失,先执行 apt-get install -f 补齐依赖后再 dpkg -i。

四、命令实测

4.1 服务端启动 —— iperf3 -s

用途:在服务端监听 5201 端口等待客户端接入。前台运行时会打印「Server listening」横幅,并在每次接入后回报传输数据。

iperf3 -s

服务端前台真实回显(本机 172.27.0.2,接收来自客户端 172.27.0.3 的一次 2 秒 TCP 测试):

-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 172.27.0.3, port 59784
[  5] local 172.27.0.2 port 5201 connected to 172.27.0.3 port 59786
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-1.00   sec  3.95 GBytes  33.9 Gbits/sec
[  5]   1.00-2.00   sec  4.09 GBytes  35.1 Gbits/sec
[  5]   2.00-12.05  sec   136 MBytes   113 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-12.05  sec  8.17 GBytes  5.83 Gbits/sec                  receiver

后台守护运行(-s -D 以守护进程方式启动,-I 指定 PID 文件,脱离终端常驻):

iperf3 -s -D -I /tmp/iperf3.pid

💡 -D(daemon)使服务端后台常驻,适合长期提供服务;结合 -1(one-off)可实现「处理一次连接后自动退出」的一次性服务。

4.2 客户端基础 TCP 测试 —— iperf3 -c 172.27.0.2

用途:客户端向服务端 172.27.0.2:5201 发起默认 10 秒的 TCP 上行测速。

参数说明:-c <host> 指定目标服务端;默认协议为 TCP、时长 10 秒(-t 默认值)、间隔 1 秒刷新一次(-i 默认 1)。

iperf3 -c 172.27.0.2
Connecting to host 172.27.0.2, port 5201
[  5] local 172.27.0.3 port 42088 connected to 172.27.0.2 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  4.02 GBytes  34.5 Gbits/sec    3   2.74 MBytes
[  5]   1.00-2.00   sec  4.04 GBytes  34.7 Gbits/sec    2   2.75 MBytes
[  5]   2.00-3.00   sec  4.14 GBytes  35.6 Gbits/sec    1   2.75 MBytes
[  5]   3.00-4.00   sec  3.60 GBytes  30.9 Gbits/sec    0   2.91 MBytes
[  5]   4.00-5.00   sec  4.15 GBytes  35.7 Gbits/sec    1   2.91 MBytes
[  5]   5.00-6.00   sec  4.10 GBytes  35.2 Gbits/sec    1   2.92 MBytes
[  5]   6.00-7.00   sec  4.03 GBytes  34.6 Gbits/sec    0   2.92 MBytes
[  5]   7.00-8.00   sec  3.91 GBytes  33.6 Gbits/sec    0   2.94 MBytes
[  5]   8.00-9.00   sec  4.11 GBytes  35.3 Gbits/sec    0   2.94 MBytes
[  5]   9.00-10.00  sec  3.91 GBytes  33.5 Gbits/sec    1   2.94 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec  40.0 GBytes  34.4 Gbits/sec    9             sender
[  5]   0.00-10.04  sec  40.0 GBytes  34.2 Gbits/sec                  receiver

iperf Done.

解读:首行 Connecting to host 172.27.0.2, port 5201 明确连接目标与端口;第二行 [ 5] local 172.27.0.3 port 42088 connected to 172.27.0.2 port 5201 为分配的连接 socket 信息(客户端源端口 42088)。中间每行是 1 秒间隔的瞬时吞吐(36GB 量级偏差来自拥塞窗口 Cwnd 的动态调整),Retr 为重传次数。底部汇总行 0.00-10.00 为整个测试期间的平均值:发送方向 40.0 GBytes / 34.4 Gbits/sec,接收方向 40.0 GBytes / 34.2 Gbits/sec。iperf Done. 表示测试正常结束(返回码 0)。

4.3 并行数据流 —— iperf3 -c 172.27.0.2 -P 4

用途:用 4 条并行 TCP 连接同时测速,模拟多连接/多核并发场景,检验单条连接之外的聚合带宽上限。

参数说明:-P <n> 指定并行流数(默认 1)。

iperf3 -c 172.27.0.2 -P 4 -t 4 -i 1
Connecting to host 172.27.0.2, port 5201
[  5] local 172.27.0.3 port 53930 connected to 172.27.0.2 port 5201
[  7] local 172.27.0.3 port 53938 connected to 172.27.0.2 port 5201
[  9] local 172.27.0.3 port 53942 connected to 172.27.0.2 port 5201
[ 11] local 172.27.0.3 port 53956 connected to 172.27.0.2 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec   966 MBytes  8.10 Gbits/sec    1   7.39 MBytes
[  7]   0.00-1.00   sec   966 MBytes  8.10 Gbits/sec    0   10.3 MBytes
[  9]   0.00-1.00   sec   966 MBytes  8.10 Gbits/sec    3   4.62 MBytes
[ 11]   0.00-1.00   sec   965 MBytes  8.09 Gbits/sec    0   10.3 MBytes
[SUM]   0.00-1.00   sec  3.77 GBytes  32.4 Gbits/sec    4
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   1.00-2.00   sec   998 MBytes  8.37 Gbits/sec    2   7.39 MBytes
[  7]   1.00-2.00   sec   998 MBytes  8.37 Gbits/sec  141   10.3 MBytes
[  9]   1.00-2.00   sec   998 MBytes  8.37 Gbits/sec    5   3.23 MBytes
[ 11]   1.00-2.00   sec   998 MBytes  8.37 Gbits/sec    2   10.3 MBytes
[SUM]   1.00-2.00   sec  3.90 GBytes  33.5 Gbits/sec  150
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   2.00-3.00   sec  1.01 GBytes  8.67 Gbits/sec    1   7.39 MBytes
[  7]   2.00-3.00   sec  1.01 GBytes  8.67 Gbits/sec    2   10.3 MBytes
[  9]   2.00-3.00   sec  1.01 GBytes  8.67 Gbits/sec    2   3.23 MBytes
[ 11]   2.00-3.00   sec  1.01 GBytes  8.67 Gbits/sec    2   10.3 MBytes
[SUM]   2.00-3.00   sec  4.04 GBytes  34.7 Gbits/sec    7
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   3.00-4.00   sec  1.10 GBytes  9.42 Gbits/sec    0   7.39 MBytes
[  7]   3.00-4.00   sec  1.10 GBytes  9.42 Gbits/sec    2   10.3 MBytes
[  9]   3.00-4.00   sec  1.09 GBytes  9.39 Gbits/sec    0   3.23 MBytes
[ 11]   3.00-4.00   sec  1.10 GBytes  9.43 Gbits/sec    1   10.3 MBytes
[SUM]   3.00-4.00   sec  4.38 GBytes  37.7 Gbits/sec    3
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-4.00   sec  4.02 GBytes  8.64 Gbits/sec    4             sender
[  5]   0.00-4.04   sec  4.02 GBytes  8.56 Gbits/sec                  receiver
[  7]   0.00-4.00   sec  4.02 GBytes  8.64 Gbits/sec  145             sender
[  7]   0.00-4.04   sec  4.02 GBytes  8.56 Gbits/sec                  receiver
[  9]   0.00-4.00   sec  4.02 GBytes  8.63 Gbits/sec   10             sender
[  9]   0.00-4.04   sec  4.02 GBytes  8.55 Gbits/sec                  receiver
[ 11]   0.00-4.00   sec  4.02 GBytes  8.64 Gbits/sec    5             sender
[ 11]   0.00-4.04   sec  4.02 GBytes  8.56 Gbits/sec                  receiver
[SUM]   0.00-4.00   sec  16.1 GBytes  34.6 Gbits/sec  164             sender
[SUM]   0.00-4.04   sec  16.1 GBytes  34.2 Gbits/sec                  receiver

iperf Done.

解读:4 条连接各分配一个 [ 5]/[ 7]/[ 9]/[ 11] 标识行,[SUM] 为四条流的聚合行。每条流约 8.6 Gbits/sec,聚合 [SUM] 16.1 GBytes / 34.6 Gbits/sec,与单流 34.4 Gbits/sec 相当——说明本机链路瓶颈不在单连接,而在总带宽(网卡/共享内核转发能力)。

4.4 UDP 模式 —— iperf3 -c 172.27.0.2 -u -b 200M

用途:UDP 测速重点评估抖动(Jitter)、丢包率,适合模拟语音/视频等实时流量。

参数说明:-u 改用 UDP;-b 200M 指定目标发送速率(UDP 默认 1 Mbit/sec,必须显式给定额度)。

iperf3 -c 172.27.0.2 -u -b 200M -t 3
Connecting to host 172.27.0.2, port 5201
[  5] local 172.27.0.3 port 33328 connected to 172.27.0.2 port 5201
[ ID] Interval           Transfer     Bitrate         Total Datagrams
[  5]   0.00-1.00   sec  23.8 MBytes   200 Mbits/sec  17252
[  5]   1.00-2.00   sec  23.8 MBytes   200 Mbits/sec  17265
[  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.002 ms  0/51782 (0%)  receiver

iperf Done.

解读:UDP 模式下每行多出 Total Datagrams(数据报数)与汇总行的 Jitter(抖动)和 Lost/Total Datagrams(丢包/总报文)。本例发送 200 Mbits/sec、共 51782 个报文,接收端抖动 0.002 ms、丢包 0/51782(0%),说明链路无拥塞、无丢包。

4.5 限速测试 —— iperf3 -c 172.27.0.2 -b 1G

用途:TCP 模式下用 -b 限速,验证链路/QoS 对限速额度的响应与丢包重传表现。

参数说明:-b <rate> 在 TCP 下限制发送速率,在 UDP 下为目标发送速率;可带 K/M/G 后缀。

iperf3 -c 172.27.0.2 -b 1G -t 3
Connecting to host 172.27.0.2, port 5201
[  5] local 172.27.0.3 port 46600 connected to 172.27.0.2 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec   119 MBytes   999 Mbits/sec    0    272 KBytes
[  5]   1.00-2.00   sec   119 MBytes  1.00 Gbits/sec    0    329 KBytes
[  5]   2.00-3.00   sec   119 MBytes  1.00 Gbits/sec    0    329 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,说明 QoS 限速生效且未引发丢包重传。对比 4.2 无限制时 34.4 Gbits/sec,-b 精确控制了发送速率——常用于验证带宽整形/限速策略。

4.6 反向模式 —— iperf3 -c 172.27.0.2 -R

用途:缺省为客户端 → 服务端发送;-R 反转为「服务端发送、客户端接收」,用于测试下行带宽。

参数说明:-R 使服务端变成发送方。

iperf3 -c 172.27.0.2 -R -t 4 -i 1
Connecting to host 172.27.0.2, port 5201
Reverse mode, remote host 172.27.0.2 is sending
[  5] local 172.27.0.3 port 40126 connected to 172.27.0.2 port 5201
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-1.00   sec  3.80 GBytes  32.7 Gbits/sec
[  5]   1.00-2.00   sec  3.64 GBytes  31.3 Gbits/sec
[  5]   2.00-3.00   sec  4.04 GBytes  34.7 Gbits/sec
[  5]   3.00-4.00   sec  3.99 GBytes  34.3 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-4.04   sec  15.5 GBytes  32.9 Gbits/sec   49             sender
[  5]   0.00-4.00   sec  15.5 GBytes  33.2 Gbits/sec                  receiver

iperf Done.

解读:输出首行 Reverse mode, remote host 172.27.0.2 is sending 提示反向模式;本次下行平均 32.9 Gbits/sec(sender 指服务端)。-R 与 -P、-b 等常组合使用。

4.7 时长与间隔 —— iperf3 -c 172.27.0.2 -t 3 -i 1

用途:-t 控制测试秒数(默认 10),-i 控制周期报告间隔秒数(默认 1),用更短时长快速完成功能验证。

参数说明:-t <sec> 测试时长;-i <sec> 周期上报间隔。

iperf3 -c 172.27.0.2 -t 3 -i 1
Connecting to host 172.27.0.2, port 5201
[  5] local 172.27.0.3 port 40158 connected to 172.27.0.2 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  3.63 GBytes  31.2 Gbits/sec    1   3.07 MBytes
[  5]   1.00-2.00   sec  3.60 GBytes  30.9 Gbits/sec    0   3.07 MBytes
[  5]   2.00-3.00   sec  3.78 GBytes  32.5 Gbits/sec    2   3.07 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-3.00   sec  11.0 GBytes  31.5 Gbits/sec    3             sender
[  5]   0.00-3.04   sec  11.0 GBytes  31.0 Gbits/sec                  receiver

iperf Done.

解读:-t 3 -i 1 只跑 3 秒、每 1 秒出一次报告,运行更快;脚本循环采集时可用更小的 -i 提高采样密度。也支持用 -n <bytes>(按字节)或 -k <count>(按报文数)替代 -t 控制测试量。

4.8 接收/发送窗口 —— iperf3 -c 172.27.0.2 -w 1M(含报错处理)

用途:-w 设置 socket 发送/接收缓冲区(窗口)大小,用于长肥管道(高带宽高延迟)场景下提升吞吐。

参数说明:-w <size> 设定窗口/套接字缓冲区大小,可带 K/M/G 后缀。

实测回显(-w 1M 报错):

iperf3 -c 172.27.0.2 -w 1M -t 3
iperf3: error - socket buffer size not set correctly
Connecting to host 172.27.0.2, 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.2 -w 200K -t 2
Connecting to host 172.27.0.2, port 5201
[  5] local 172.27.0.3 port 40154 connected to 172.27.0.2 port 5201
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-2.00   sec  6.35 GBytes  27.3 Gbits/sec   43             sender
[  5]   0.00-2.04   sec  6.35 GBytes  26.7 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.2 -l 64K

用途:-l 指定单次读写的缓冲区/报文长度。TCP 默认 128 KB;调整后可观察不同报文分节对吞吐的影响。

参数说明:-l <len> 设置读写缓冲区长度。

iperf3 -c 172.27.0.2 -l 64K -t 3
Connecting to host 172.27.0.2, port 5201
[  5] local 172.27.0.3 port 40158 connected to 172.27.0.2 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  3.39 GBytes  29.1 Gbits/sec    0   3.07 MBytes
[  5]   1.00-2.00   sec  3.63 GBytes  31.2 Gbits/sec    0   3.07 MBytes
[  5]   2.00-3.00   sec  3.60 GBytes  30.9 Gbits/sec   49   3.07 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-3.00   sec  10.6 GBytes  30.4 Gbits/sec   49             sender
[  5]   0.00-3.04   sec  10.6 GBytes  30.0 Gbits/sec                  receiver

iperf Done.

解读:改用 64 KB 缓冲后平均 30.4 Gbits/sec,与默认 128 KB 的 31~34 Gbits/sec 相当,说明本机场景下缓冲长度对吞吐影响有限。

4.10 自定义端口 —— iperf3 -c 172.27.0.2 -p 5202

用途:默认服务端监听/客户端连接 5201;-p 可指定其他端口,便于多实例、多场景并存。

参数说明:客户端 -p <port> 与 -c 连目标端口;服务端需先用 iperf3 -s -p 5202 在同端口监听。

服务端用 5202 端口监听:

iperf3 -s -p 5202

客户端连接 172.27.0.2:5202:

iperf3 -c 172.27.0.2 -p 5202 -t 3
Connecting to host 172.27.0.2, port 5202
[  5] local 172.27.0.3 port 49296 connected to 172.27.0.2 port 5202
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  3.90 GBytes  33.5 Gbits/sec    0   3.83 MBytes
[  5]   1.00-2.00   sec  3.90 GBytes  33.5 Gbits/sec    2   3.83 MBytes
[  5]   2.00-3.00   sec  3.94 GBytes  33.9 Gbits/sec  192   3.83 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-3.00   sec  11.7 GBytes  33.6 Gbits/sec  194             sender
[  5]   0.00-13.04  sec  11.7 GBytes  7.73 Gbits/sec                  receiver

iperf Done.

解读:首行 port 5202 确认连到自定义端口;其余输出结构与 5201 一致。注意同一端口只能被一个服务端实例占用。

4.11 省略起始段 —— iperf3 -c 172.27.0.2 -O 1

用途:-O N 在统计中省略前 N 秒,避开枚举/建链/拥塞窗口爬升等「预热期」,让平均吞吐更能体现稳定状态。

参数说明:-O <N> 报告时省略前 N 秒(不影响总时长)。

iperf3 -c 172.27.0.2 -O 1 -t 4 -i 1
Connecting to host 172.27.0.2, port 5201
[  5] local 172.27.0.3 port 56812 connected to 172.27.0.2 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  3.75 GBytes  32.2 Gbits/sec    1   3.90 MBytes       (omitted)
[  5]   0.00-1.00   sec  3.78 GBytes  32.5 Gbits/sec    1   3.90 MBytes
[  5]   1.00-2.00   sec  3.94 GBytes  33.9 Gbits/sec    1   3.90 MBytes
[  5]   2.00-3.00   sec  4.06 GBytes  34.9 Gbits/sec    1   3.90 MBytes
[  5]   3.00-4.00   sec  4.12 GBytes  35.4 Gbits/sec    0   3.90 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-4.00   sec  15.9 GBytes  34.1 Gbits/sec    3             sender
[  5]   0.00-14.05  sec  16.0 GBytes  9.81 Gbits/sec                  receiver

iperf Done.

解读:第 1 秒的间隔行被标记为 (omitted)(仅显示、不参与平均),其余行正常上报。

4.12 JSON 结构化输出 —— iperf3 -c 172.27.0.2 -J

用途:-J 以 JSON 输出完整结果,机器可解析,方便脚本/监控系统消费;--logfile <file> 可将日志写入文件,配合 --forceflush 每次间隔实时落盘。

参数说明:-J 输出 JSON。

iperf3 -c 172.27.0.2 -t 3 -i 1 -J
{
        "start":        {
                "connected":    [{
                                "socket":       5,
                                "local_host":   "172.27.0.3",
                                "local_port":   33986,
                                "remote_host":  "172.27.0.2",
                                "remote_port":  5201
                        }],
                "version":      "iperf 3.9",
                "system_info":  "Linux 172.27.0.3 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:28:53 GMT",
                        "timesecs":     1791520133
                },
                "connecting_to":        {
                        "host": "172.27.0.2",
                        "port": 5201
                },
                "cookie":       "2txgqlb43y5wa3wrs72uk5e3erwqehszx2ve",
                "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":     3,
                        "bytes":        0,
                        "blocks":       0,
                        "reverse":      0,
                        "tos":  0
                }
        },
        "intervals":    [{
                        "streams":      [{
                                        "socket":       5,
                                        "start":        0,
                                        "end":  1.000113,
                                        "seconds":      1.0001130104064941,
                                        "bytes":        4321443840,
                                        "bits_per_second":      34567644216.475548,
                                        "retransmits":  114,
                                        "snd_cwnd":     847080,
                                        "rtt":  36,
                                        "rttvar":       10,
                                        "pmtu": 1500,
                                        "omitted":      false,
                                        "sender":       true
                                }],
                        "sum":  {
                                "start":        0,
                                "end":  1.000113,
                                "seconds":      1.0001130104064941,
                                "bytes":        4321443840,
                                "bits_per_second":      34567644216.475548,
                                "retransmits":  114,
                                "omitted":      false,
                                "sender":       true
                        }
                }],
        "end":  {
                "streams":      [{
                                "sender":       {
                                        "socket":       5,
                                        "start":        0,
                                        "end":  3.000123,
                                        "seconds":      3.000123,
                                        "bytes":        12592087040,
                                        "bits_per_second":      33577522094.927444,
                                        "retransmits":  114,
                                        "max_snd_cwnd": 1051248,
                                        "max_rtt":      58,
                                        "min_rtt":      36,
                                        "mean_rtt":     45,
                                        "sender":       true
                                },
                                "receiver":     {
                                        "socket":       5,
                                        "start":        0,
                                        "end":  3.040217,
                                        "seconds":      3.000123,
                                        "bytes":        12591300608,
                                        "bits_per_second":      33132636540.089077,
                                        "sender":       true
                                }
                        }],
                "sum_sent":     {
                        "start":        0,
                        "end":  3.000123,
                        "seconds":      3.000123,
                        "bytes":        12592087040,
                        "bits_per_second":      33577522094.927444,
                        "retransmits":  114,
                        "sender":       true
                },
                "sum_received": {
                        "start":        0,
                        "end":  3.040217,
                        "seconds":      3.040217,
                        "bytes":        12591300608,
                        "bits_per_second":      33132636540.089077,
                        "sender":       true
                },
                "cpu_utilization_percent":      {
                        "host_total":   95.373128613298235,
                        "host_user":    2.5201578883151745,
                        "host_system":  92.852938275066265,
                        "remote_total": 25.868867702630428,
                        "remote_user":  2.04338583066452,
                        "remote_system":        23.825471884205907
                },
                "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(帮助全文,Ubuntu 22.04 / 3.9 版)

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
  --timestamps    <format>  emit a timestamp at the start of each output line
                            (using optional format string as per strftime(3))
  -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
  --server-bitrate-limit #[KMG][/#]   server's total bit rate limit (default 0 = no limit)
                            (optional slash and number of secs interval for averaging
                            total data rate.  Default is 5 seconds)
  --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
  --use-pkcs1-padding       use pkcs1 padding at your own risk
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.
  --dscp N or --dscp val    set the IP dscp value, either 0-63 or symbolic.
                            Numeric values can be specified in decimal,
                            octal and hex (see --tos above).
  -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
  --extra-data str          data string to include in client and server JSON
  --get-server-output       get results from server
  --udp-counters-64bit      use 64-bit counters in UDP test packets
  --repeating-payload       use repeating pattern in payload, instead of
                            randomized payload (like in iperf2)
  --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: https://software.es.net/iperf/
Report bugs to:     https://github.com/esnet/iperf

5.2 版本信息 —— iperf3 -v

iperf 3.9 (cJSON 1.7.13)
Linux 172.27.0.3 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 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 -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.3 输出吞吐「虚高」

Q:内网测出来几十 Gbps,看起来不真实? A:iperf3 测到的是路径当前能达到的吞吐。在同一内网段、共享转发路径且无瓶颈时,值偏高属正常;要得到贴近运营商的真实带宽,应在被测链路两端(网卡到网卡、跨交换机)对测,并结合多流 -P、UDP -u、反向 -R 交叉验证。

6.4 UDP 与 TCP 结果差异

Q:UDP 限 200M 很稳,TCP 却飙到 30G? A:UDP 按 -b 限定的速率主动发包(UDP 默认 1 Mbit),是"先限速再测";TCP 无 -b 时默认不限速(尽力而为),测的是链路能塞满的上限。两者用途不同:UDP 多用于抖动/丢包与实时业务模拟,TCP 用于带宽/吞吐基线。

七、参考链接