网络性能测试工具iperf3简介、安装、使用

一、iperf3简介

概念

        iperf3是一种网络性能测试工具,它可以用于测试TCP和UDP带宽、延迟和数据包丢失率等网络性能指标。它是iperf的新版本,相对于旧版本,iperf3增加了一些新特性和改进,例如支持IPv6、多线程、流媒体模式、JSON输出等。使用iperf3可以帮助管理员评估网络性能、排除故障和优化网络配置。

        iperf3是一个基于命令行的网络性能测试工具,用于测量TCP和UDP吞吐量,延迟和抖动(jitter)。它支持IPv4和IPv6,多种传输协议,包括TCP,UDP和SCTP。iperf3是iperf的新版本,相对于旧版本,具有更多的功能和改进。

支持功能:

  • 测试TCP和UDP吞吐量、延迟和抖动
  • 支持IPv4和IPv6
  • 支持多个传输协议,包括TCP,UDP和SCTP
  • 支持同时使用多个线程进行测试,以更好地模拟真实的网络流量
  • 支持流媒体模式,可用于测试实时流传输
  • 支持JSON输出格式,方便对测试结果进行分析和处理

优点:

  • 简单易用,只需要通过命令行来实现测试
  • 支持多种传输协议和IPv4/IPv6,可用于测试各种网络环境
  • 可以同时使用多个线程进行测试,提高测试效率
  • 支持流媒体模式和JSON输出格式,方便定制测试和分析测试结果

缺点:

  • 只能通过命令行进行操作,对于不熟悉命令行的用户可能不够友好
  • 测试结果可能会受到其他因素的影响,如网络质量、路由器性能等

应用场景:

  • 网络管理员可以使用iperf3测试网络吞吐量来评估网络性能和带宽利用率
  • 开发人员可以使用iperf3测试自己应用程序在各种网络条件下的性能表现
  • 执行故障排除时,可以使用iperf3帮助确定网络问题的原因
  • 在网络优化和升级中,可以使用iperf3来测试不同配置之间的性能差异

二、CentOS系统上安装和使用iperf3

下面是在Linux环境下CentOS系统上安装和使用iperf3的示例:

  1. 安装iperf3

在终端中输入以下命令来安装iperf3:

sudo yum install iperf3

        2. 运行iperf3测试

a. 启动iperf3服务器:

在需要测试的服务器上启动iperf3服务器,以监听来自客户端的测试请求。在服务器终端中输入以下命令:

iperf3 -s

b. 连接到iperf3服务器进行测试:

在客户端终端中输入以下命令来连接到服务器进行测试:

iperf3 -c <server_ip>

其中,&lt;server_ip>是你需要测试的服务器的IP地址。执行以上命令后,会显示测试结果,包括带宽、延迟、抖动等信息。

[root@localhost netperf-netperf-2.7.0]# yum install iperf3
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.bupt.edu.cn
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.bupt.edu.cn
 * updates: mirrors.bupt.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 iperf3.x86_64.0.3.1.7-2.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=========================================================================================================================
 Package                    架构                       版本                               源                        大小
=========================================================================================================================
正在安装:
 iperf3                     x86_64                     3.1.7-2.el7                        base                      79 k

事务概要
=========================================================================================================================
安装  1 软件包

总下载量:79 k
安装大小:197 k
Is this ok [y/d/N]: y
Downloading packages:
iperf3-3.1.7-2.el7.x86_64.rpm                                                                     |  79 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : iperf3-3.1.7-2.el7.x86_64                                                                            1/1 
  验证中      : iperf3-3.1.7-2.el7.x86_64                                                                            1/1 

已安装:
  iperf3.x86_64 0:3.1.7-2.el7                                                                                            

完毕!
[root@localhost netperf-netperf-2.7.0]# 
[root@localhost netperf-netperf-2.7.0]# iperf3 -v
iperf 3.1.7
Linux localhost.localdomain 3.10.0-1160.71.1.el7.x86_64 #1 SMP Tue Jun 28 15:37:28 UTC 2022 x86_64
Optional features available: CPU affinity setting, IPv6 flow label, TCP congestion algorithm setting, sendfile / zerocopy, socket pacing
[root@localhost netperf-netperf-2.7.0]# 
[root@localhost netperf-netperf-2.7.0]# iperf3 -s
-----------------------------------------------------------
Server listening on 5201

        3. 更多选项

参考iperf3的帮助文档,可以使用更多选项来定制测试,例如:

  • 使用UDP传输模式:iperf3 -u -c &lt;server_ip>
  • 指定测试时间:iperf3 -t &lt;time_in_seconds> -c &lt;server_ip>
  • 指定测试端口:iperf3 -p &lt;port_number> -c &lt;server_ip>

Server:

[root@localhost ~]# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 192.168.6.212, port 56144
[  5] local 192.168.6.211 port 5201 connected to 192.168.6.212 port 59248
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  5]   0.00-1.01   sec   117 KBytes   955 Kbits/sec  1421.423 ms  0/83 (0%)  
[  5]   1.01-2.01   sec   127 KBytes  1.04 Mbits/sec  4.691 ms  0/90 (0%)  
[  5]   2.01-3.01   sec   129 KBytes  1.06 Mbits/sec  0.069 ms  0/91 (0%)  
[  5]   3.01-4.01   sec   127 KBytes  1.04 Mbits/sec  0.444 ms  0/90 (0%)  
[  5]   4.01-5.02   sec   129 KBytes  1.05 Mbits/sec  0.061 ms  0/91 (0%)  
[  5]   5.02-6.01   sec   129 KBytes  1.06 Mbits/sec  0.196 ms  0/91 (0%)  
[  5]   6.01-7.02   sec   127 KBytes  1.03 Mbits/sec  0.065 ms  0/90 (0%)  
[  5]   7.02-8.01   sec   130 KBytes  1.08 Mbits/sec  0.146 ms  0/92 (0%)  
[  5]   8.01-9.01   sec   126 KBytes  1.02 Mbits/sec  0.059 ms  0/89 (0%)  
[  5]   9.01-10.01  sec   129 KBytes  1.06 Mbits/sec  0.057 ms  0/91 (0%)  
[  5]  10.01-10.06  sec  0.00 Bytes  0.00 bits/sec  0.057 ms  0/0 (0%)  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  5]   0.00-10.06  sec  0.00 Bytes  0.00 bits/sec  0.057 ms  0/898 (0%)  
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 192.168.6.212, port 56146
[  5] local 192.168.6.211 port 5201 connected to 192.168.6.212 port 56148
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec   313 MBytes  2.62 Gbits/sec                  
[  5]   1.00-2.00   sec   319 MBytes  2.67 Gbits/sec                  
[  5]   2.00-3.02   sec   361 MBytes  2.99 Gbits/sec                  
[  5]   3.02-4.00   sec   363 MBytes  3.10 Gbits/sec                  
[  5]   4.00-5.01   sec   379 MBytes  3.16 Gbits/sec                  
[  5]   5.01-5.04   sec  6.85 MBytes  1.80 Gbits/sec                  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-5.04   sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-5.04   sec  1.70 GBytes  2.90 Gbits/sec                  receiver
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 192.168.6.212, port 56150
[  5] local 192.168.6.211 port 5201 connected to 192.168.6.212 port 56152
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec   278 MBytes  2.33 Gbits/sec                  
[  5]   1.00-2.00   sec   351 MBytes  2.94 Gbits/sec                  
[  5]   2.00-3.00   sec   374 MBytes  3.13 Gbits/sec                  
[  5]   3.00-4.00   sec   396 MBytes  3.32 Gbits/sec                  
[  5]   4.00-5.00   sec   371 MBytes  3.11 Gbits/sec                  
[  5]   5.00-6.00   sec   406 MBytes  3.40 Gbits/sec                  
[  5]   6.00-7.01   sec   381 MBytes  3.19 Gbits/sec                  
[  5]   7.01-8.00   sec   376 MBytes  3.17 Gbits/sec                  
[  5]   8.00-9.00   sec   378 MBytes  3.17 Gbits/sec                  
[  5]   9.00-10.00  sec   372 MBytes  3.12 Gbits/sec                  
[  5]  10.00-10.05  sec  19.4 MBytes  3.57 Gbits/sec                  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-10.05  sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-10.05  sec  3.61 GBytes  3.09 Gbits/sec                  receiver
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

Client:

[root@localhost ~]# iperf3 -u -c 192.168.6.211
Connecting to host 192.168.6.211, port 5201
[  4] local 192.168.6.212 port 59248 connected to 192.168.6.211 port 5201
[ ID] Interval           Transfer     Bandwidth       Total Datagrams
[  4]   0.00-1.02   sec   117 KBytes   944 Kbits/sec  83  
[  4]   1.02-2.03   sec   127 KBytes  1.03 Mbits/sec  90  
[  4]   2.03-3.02   sec   129 KBytes  1.07 Mbits/sec  91  
[  4]   3.02-4.03   sec   127 KBytes  1.03 Mbits/sec  90  
[  4]   4.03-5.01   sec   129 KBytes  1.07 Mbits/sec  91  
[  4]   5.01-6.02   sec   129 KBytes  1.05 Mbits/sec  91  
[  4]   6.02-7.01   sec   127 KBytes  1.05 Mbits/sec  90  
[  4]   7.01-8.02   sec   130 KBytes  1.06 Mbits/sec  92  
[  4]   8.02-9.01   sec   126 KBytes  1.04 Mbits/sec  89  
[  4]   9.01-10.02  sec   129 KBytes  1.05 Mbits/sec  91  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-10.02  sec  1.24 MBytes  1.04 Mbits/sec  0.057 ms  0/898 (0%)  
[  4] Sent 898 datagrams

iperf Done.
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# iperf3 -t 5 -c 192.168.6.211
Connecting to host 192.168.6.211, port 5201
[  4] local 192.168.6.212 port 56148 connected to 192.168.6.211 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   323 MBytes  2.71 Gbits/sec    0    911 KBytes       
[  4]   1.00-2.01   sec   321 MBytes  2.68 Gbits/sec    0   1.24 MBytes       
[  4]   2.01-3.00   sec   366 MBytes  3.09 Gbits/sec    0   1.46 MBytes       
[  4]   3.00-4.00   sec   368 MBytes  3.07 Gbits/sec    0   1.60 MBytes       
[  4]   4.00-5.00   sec   368 MBytes  3.09 Gbits/sec    0   1.69 MBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-5.00   sec  1.70 GBytes  2.93 Gbits/sec    0             sender
[  4]   0.00-5.00   sec  1.70 GBytes  2.92 Gbits/sec                  receiver

iperf Done.
[root@localhost ~]# 
[root@localhost ~]# iperf3 -p 5201 -c 192.168.6.211
Connecting to host 192.168.6.211, port 5201
[  4] local 192.168.6.212 port 56152 connected to 192.168.6.211 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.01   sec   305 MBytes  2.54 Gbits/sec    0    848 KBytes       
[  4]   1.01-2.00   sec   344 MBytes  2.90 Gbits/sec    0   1.21 MBytes       
[  4]   2.00-3.00   sec   375 MBytes  3.14 Gbits/sec    0   1.46 MBytes       
[  4]   3.00-4.00   sec   398 MBytes  3.34 Gbits/sec    0   1.58 MBytes       
[  4]   4.00-5.00   sec   370 MBytes  3.10 Gbits/sec    0   1.67 MBytes       
[  4]   5.00-6.00   sec   416 MBytes  3.49 Gbits/sec    0   1.73 MBytes       
[  4]   6.00-7.00   sec   366 MBytes  3.08 Gbits/sec    2   1.31 MBytes       
[  4]   7.00-8.00   sec   381 MBytes  3.20 Gbits/sec    0   1.45 MBytes       
[  4]   8.00-9.00   sec   376 MBytes  3.15 Gbits/sec    0   1.52 MBytes       
[  4]   9.00-10.00  sec   376 MBytes  3.16 Gbits/sec    0   1.60 MBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  3.62 GBytes  3.11 Gbits/sec    2             sender
[  4]   0.00-10.00  sec  3.61 GBytes  3.10 Gbits/sec                  receiver

iperf Done.
[root@localhost ~]#

解释:

Connecting to host 192.168.6.211, port 5201
[  4] local 192.168.6.212 port 56152 connected to 192.168.6.211 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.01   sec   305 MBytes  2.54 Gbits/sec    0    848 KByte
  • 第一行显示了iperf3客户端正在连接的目标主机IP地址(192.168.6.211)和端口号(5201)。
  • 第二行显示了客户端本地IP地址(192.168.6.212)和使用的本地端口号(56152),以及已经连接的目标主机IP地址(192.168.6.211)和端口号(5201)。
  • 第三行显示了数据传输的时间间隔(0.00-1.01秒)、传输的数据量(305MB)、传输速率(2.54Gbits/sec)、重传的数据包数(0)和TCP拥塞控制窗口大小(848KB)。
Accepted connection from 192.168.6.212, port 56150
[  5] local 192.168.6.211 port 5201 connected to 192.168.6.212 port 56152
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec   278 MBytes  2.33 Gbits/sec                  
[  5]   1.00-2.00   sec   351 MBytes  2.94 Gbits/sec 
  • 第一行显示了iperf3服务器端已经接受了来自192.168.6.212的连接请求,并使用本地端口56150进行通信。
  • 第二行显示了服务器端本地IP地址(192.168.6.211)和使用的本地端口号(5201),以及已经连接的客户端IP地址(192.168.6.212)和端口号(56152)。
  • 第三行显示了数据传输的时间间隔(0.00-1.00秒)、传输的数据量(278MB)和传输速率(2.33 Gbits/sec)。
  • 第四行显示了数据传输的时间间隔(1.00-2.00秒)、传输的数据量(351MB)和传输速率(2.94 Gbits/sec)。

三、iperf3参数说明

以下是iperf3的参数和对应的说明:

  • -p, --port <port>:指定服务器和客户端之间使用的端口号,默认为 5201。
  • -f, --format [kmKM]:指定带宽格式以展示结果。默认为Mbits/sec,可选项包括 Kbits/sec、Mbits/sec、Gbits/sec 和 KBytes/sec、MBytes/sec、GBytes/sec。
  • -i, --interval <n>:指定间隔时间,每隔多久显示一次带宽信息,默认为1秒。
  • -w, --window <n>:指定TCP窗口大小,默认为 128KB。
  • -t, --time <n>:指定测试时间,单位为秒,默认为10秒。
  • -c, --client <host>:指定客户端对应的服务器IP/主机名。如果未指定,则运行在服务器模式(即 -s)
  • -V, --version:显示iperf3版本信息。
  • -b, --bitrate <bitrate>:指定UDP传输模式下的比特率,可选项包括 bps、Kbps、Mbps 和 Gbps,比如 1G。
  • -u, --udp:使用UDP进行测试。
  • -R, --reverse:反向测试,其用法与 -d 相同,但是服务端将变为发送而不是接收数据。
  • -d, --dualtest:进行双向测试。即服务器和客户端在同一时间并发进行上传和下载操作。
  • -S, --tos <s>:设置服务类型(TOS)的值。
  • -Z, --zerocopy:使用零拷贝模式来发送数据。
  • -B, --bind <host>:在指定的IP地址上进行绑定,等待请求。
  • -M, --set-mss <value>:指定TCP最大报文段大小,即MSS值。
  • -N, --nodelay:禁用 Nagle 算法,以最小化延迟。
  • -P, --parallel <n>:指定并行连接数,执行多个测试并发地进行。
  • -T, --ttl <value>:指定 Time To Live(TTL)值,定义 IP 数据包的寿命。
  • -h, --help:显示帮助信息。

使用这些参数的示例命令:

  • TCP模式下进行10秒长的测试:iperf3 -c 192.168.1.2 -t 10
  • UDP模式下指定比特率和时间:iperf3 -c 192.168.1.2 -u -b 10G -t 5
  • 指定双向测试:iperf3 -c 192.168.1.2 -d
  • 指定并行连接数:iperf3 -c 192.168.1.2 -P 5
  • 反向测试:iperf3 -c 192.168.1.2 -R
  • 绑定到特定IP地址:iperf3 -c 192.168.1.2 -B 10.0.0.100
  • 使用零拷贝模式:iperf3 -c 192.168.1.2 -Z
  • 显示帮助信息:iperf3 -h

猜你喜欢

转载自blog.csdn.net/songpeiying/article/details/131830185