iperf3相互打流
iperf3 是一个用于测量网络带宽的工具,常用于对打流测试(即在两台设备之间进行网络性能测试)。以下是如何使用 iperf3 进行对打流测试的步骤:
1. 环境准备
- 设备A:作为服务器端(接收端)。
- 设备B:作为客户端(发送端)。
- 两台设备需要在同一网络中,并且能够互相通信。
2. 安装 iperf3
在两台设备上都需要安装 iperf3。安装方法取决于操作系统:
在 Ubuntu/Debian 上:
| Bash | 
|---|
|  | sudo apt-get update
sudo apt-get install iperf3
 | 
在 CentOS/RHEL 上:
在 macOS 上:
3. 启动 iperf3 服务器
在设备A(服务器端)上启动 iperf3 服务器,并指定监听的IP地址和端口。
| Bash | 
|---|
|  | iperf3 -s -B <服务器IP地址> -p <端口号>
 | 
例如,如果设备A的IP地址是 192.168.1.100,并且你想监听在 5202 端口,则命令为:
| Bash | 
|---|
|  | iperf3 -s -B 192.168.1.100 -p 5202
 | 
4. 启动 iperf3 客户端
在设备B(客户端)上启动 iperf3 客户端,并连接到设备A的服务器,指定服务器的IP地址和端口。
| Bash | 
|---|
|  | iperf3 -c <服务器IP地址> -p <端口号>
 | 
例如,如果设备A的IP地址是 192.168.1.100,并且服务器监听在 5202 端口,则命令为:
| Bash | 
|---|
|  | iperf3 -c 192.168.1.100 -p 5202
 | 
5. 测试参数
你可以根据需要调整测试参数,例如:
- 测试时间:默认测试时间为10秒,可以使用 -t参数指定时间(单位:秒)。
| Bash | 
|---|
|  | iperf3 -c 192.168.1.100 -p 5202 -t 60  # 测试60秒
 | 
- 带宽限制:使用 -b参数限制带宽(单位:比特/秒)。
| Bash | 
|---|
|  | iperf3 -c 192.168.1.100 -p 5202 -b 100M  # 限制带宽为100Mbps
 | 
| Bash | 
|---|
|  | iperf3 -c 192.168.1.100 -p 5202 -d
 | 
| Bash | 
|---|
|  | iperf3 -c 192.168.1.100 -p 5202 -u
 | 
6. 结果分析
测试完成后,iperf3 会输出详细的测试结果,包括带宽、丢包率、延迟等信息。
7. 停止测试
测试完成后,可以按 Ctrl+C 停止 iperf3 服务器。
8. 其他注意事项
- 防火墙设置:确保两台设备之间的防火墙允许指定的端口通信。
- 网络环境:确保网络环境稳定,避免其他网络活动干扰测试结果。
示例
假设设备A的IP地址是 192.168.1.100,设备B的IP地址是 192.168.1.101,并且你想在 5202 端口进行测试。
在设备A上启动服务器:
| Bash | 
|---|
|  | iperf3 -s -B 192.168.1.100 -p 5202
 | 
在设备B上启动客户端:
| Bash | 
|---|
|  | iperf3 -c 192.168.1.100 -p 5202 -t 60
 | 
通过以上步骤,你可以在两台设备之间进行对打流测试,并自定义IP地址和端口,评估网络性能。
查看结果
| Text Only | 
|---|
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20 | [root@localhost ~]# iperf3 -s -B 192.168.1.170 -p 5202
-----------------------------------------------------------
Server listening on 5202 (test #1)
-----------------------------------------------------------
Accepted connection from 192.168.1.22, port 40372
[  5] local 192.168.1.170 port 5202 connected to 192.168.1.22 port 40384
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-1.00   sec   112 MBytes   941 Mbits/sec
[  5]   1.00-2.00   sec   112 MBytes   942 Mbits/sec
[  5]   2.00-3.00   sec   112 MBytes   942 Mbits/sec
[  5]   3.00-4.00   sec   112 MBytes   942 Mbits/sec
[  5]   4.00-5.00   sec   112 MBytes   941 Mbits/sec
[  5]   5.00-6.00   sec   112 MBytes   942 Mbits/sec
[  5]   6.00-7.00   sec   112 MBytes   942 Mbits/sec
[  5]   7.00-8.00   sec   112 MBytes   942 Mbits/sec
[  5]   8.00-9.00   sec   112 MBytes   942 Mbits/sec
[  5]   9.00-10.00  sec   112 MBytes   941 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-10.00  sec  1.10 GBytes   941 Mbits/sec                  receiver
 | 
| Text Only | 
|---|
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 | [root@localhost ~]# ethtool  enp135s0f1
Settings for enp135s0f1:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supported pause frame use: Symmetric
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: Symmetric
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: off (auto)
        Supports Wake-on: pumbg
        Wake-on: g
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes
 | 
结果显示:打流平均速率941 Mbits/sec和网卡Speed: 1000Mb/s相近,符合