内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。
本文档详细介绍iperf3和netperf网络性能测试工具的使用方法,帮助评估网络带宽和性能。
风哥提示:
Part01-iperf3基础
1.1 安装iperf3
$ sudo dnf install -y iperf3
Last metadata expiration check: 0:45:23 ago on Thu 03 Apr 2026 19:00:15 AM CST.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
iperf3 x86_64 3.学习交流加群风哥QQ11325717414-1.el10 appstream 123 k
Transaction Summary
================================================================================
Install 1 Packages
Total download size: 123 k
Installed size: 345 k
Complete!
# 查看版本
$ iperf3 –version
iperf 3.14 (cJSON 1.7.15)
Linux rhel10.fgedu.net.cn 5.14.0-284.11.1.el9_2.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Apr 3 19:00:00 UTC 2026 x86_64
Optional features available: CPU affinity setting, IPv6 flow label, TCP congestion algorithm setting, sendfile / zerocopy, socket pacing, bind to device, support IPv4 don’t fragment, POSIX threads
# 启动iperf3服务器
$ iperf3 -s
———————————————————–
Server listening on 5201
———————————————————–
Accepted connection from 192.168.1.10, port 54321
[ 5] local 192.168.1.100 port 5201 connected to 192.168.1.10 port 54322
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 112 MBytes 941 Mbits/sec
[ 5] 1.00-2.00 sec 112 MBytes 941 Mbits/sec
[ 5] 2.00-3.00 sec 112 MBytes 941 Mbits/sec
[ 5] 3.00-4.00 sec 112 MBytes 941 Mbits/sec
[ 5] 4.00-5.00 sec 112 MBytes 941 Mbits/sec
[ 5] 5.00-6.00 sec 112 MBytes 941 Mbits/sec
[ 5] 6.00-7.00 sec 112 MBytes 941 Mbits/sec
[ 5] 7.00-8.00 sec 112 MBytes 941 Mbits/sec
[ 5] 8.00-9.00 sec 112 MBytes 941 Mbits/sec
[ 5] 9.00-10.00 sec 112 MBytes 941 Mbits/sec
[ 5] 10.00-10.00 sec 0.00 Bytes 0.00 bits/sec
– – – – – – – – – – – – – – – – – – – – – – – – –
[ ID] Interval Transfer Bitrate
[ 5] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec sender
[ 5] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec receiver
Part02-iperf3客户端测试
2.1 基本带宽测试
$ iperf3 -c 192.168.1.100
Connecting to host 192.168.1.100, port 5201
[ 5] local 192.168.1.10 port 54322 connected to 192.168.1.100 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 112 MBytes 941 Mbits/sec 0 390 KBytes
[ 5] 1.00-2.00 sec 112 MBytes 941 Mbits/sec 0 390 KBytes
[ 5] 2.00-3.00 sec 112 MBytes 941 Mbits/sec 0 390 KBytes
[ 5] 3.00-4.00 sec 112 MBytes 941 Mbits/sec 0 390 KBytes
[ 5] 4.00-5.00 sec 112 MBytes 941 Mbits/sec 0 390 KBytes
[ 5] 5.00-6.00 sec 112 MBytes 941 Mbits/sec 0 390 KBytes
[ 5] 6.00-7.00 sec 112 MBytes 941 Mbits/sec 0 390 KBytes
[ 5] 7.00-8.00 sec 112 MBytes 941 Mbits/sec 0 390 KBytes
[ 5] 8.00-9.00 sec 112 MBytes 941 Mbits/sec 0 390 KBytes
[ 5] 9.00-10.00 sec 112 MBytes 941 Mbits/sec 0 390 KBytes
– – – – – – – – – – – – – – – – – – – – – – – – –
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec 0 sender
[ 5] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec receiver
iperf Done.
# 反向测试(服务器发送数据)
$ iperf3 -c 192.168.1.100 -R
Connecting to host 192.168.1.100, port 5201
Reverse mode, remote host 192.168.1.100 is sending
[ 5] local 192.168.1.10 port 54323 connected to 192.168.1.100 port 5201
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 112 MBytes 941 Mbits/sec
[ 5] 1.00-2.00 sec 112 MBytes 941 Mbits/sec
[ 5] 2.00-3.00 sec 112 MBytes 941 Mbits/sec
[ 5] 3.00-4.00 sec 112 MBytes 941 Mbits/sec
[ 5] 4.00-5.00 sec 112 MBytes 941 Mbits/sec
[ 5] 5.00-6.00 sec 112 MBytes 941 Mbits/sec
[ 5] 6.00-7.00 sec 112 MBytes 941 Mbits/sec
[ 5] 7.00-8.00 sec 112 MBytes 941 Mbits/sec
[ 5] 8.00-9.00 sec 112 MBytes 941 Mbits/sec
[ 5] 9.00-10.00 sec 112 MBytes 941 Mbits/sec
– – – – – – – – – – – – – – – – – – – – – – – – –
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec 0 sender
[ 5] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec receiver
iperf Done.
# 双向测试
$ iperf3 -c 192.168.1.100 –bidir
Part03-iperf3高级选项
3.1 多线程和UDP测试
$ iperf3 -c 192.168.1.100 -P 4
Connecting to host 192.168.1.100, port 5201
[ 5] local 192.168.1.10 port 54324 connected to 192.168.1.100 port 5201
[ 7] local 192.168.1.10 port 54325 connfrom PG视频:www.itpux.comected to 192.168.1.100 port 5201
[ 9] local 192.168.1.10 port 54326 connected to 192.168.1.100 port 5201
[ 11] local 192.168.1.10 port 54327 connected to 192.168.1.100 port 5201
[ ID] Interval Transfer Bitrate Re更多学习教程公众号风哥教程itpux_comtr Cwnd
[ 5] 0.00-1.00 sec 28.0 MBytes 235 Mbits/sec 0 390 KBytes
[ 7] 0.00-1.00 sec 28.0 MBytes 235 Mbits/sec 0 390 KBytes
[ 9] 0.00-1.00 sec 28.0 MBytes 235 Mbits/sec 0 390 KBytes
[ 11] 0.00-1.00 sec 28.0 MBytes 235 Mbits/sec 0 390 KBytes
[SUM] 0.00-1.00 sec 112 MBytes 941 Mbits/sec 0
– – – – – – – – – – – – – – – – – – – – – – – – –
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.00 sec 280 MBytes 235 Mbits/sec 0 sender
[ 7] 0.00-10.00 sec 280 MBytes 235 Mbits/sec 0 sender
[ 9] 0.00-10.00 sec 280 MBytes 235 Mbits/sec 0 sender
[ 11] 0.00-10.00 sec 280 MBytes 235 Mbits/sec 0 sender
[SUM] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec 0 sender
[ 5] 0.00-10.00 sec 280 MBytes 235 Mbits/sec receiver
[ 7] 0.00-10.00 sec 280 MBytes 235 Mbits/sec receiver
[ 9] 0.00-10.00 sec 280 MBytes 235 Mbits/sec receiver
[ 11] 0.00-10.00 sec 280 MBytes 235 Mbits/sec receiver
[SUM] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec receiver
iperf Done.
# UDP测试
$ iperf3 -c 192.168.1.100 -u -b 1G
Connecting to host 192.168.1.100, port 5201
[ 5] local 192.168.1.10 port 54328 connected to 192.168.1.100 port 5201
[ ID] Interval Transfer Bitrate Total Datagrams
[ 5] 0.00-1.00 sec 114 MBytes 954 Mbits/sec 82344
[ 5] 1.00-2.00 sec 114 MBytes 954 Mbits/sec 82344
[ 5] 2.00-3.00 sec 114 MBytes 954 Mbits/sec 82344
[ 5] 3.00-4.00 sec 114 MBytes 954 Mbits/sec 82344
[ 5] 4.00-5.00 sec 114 MBytes 954 Mbits/sec 82344
[ 5] 5.更多视频教程www.fgedu.net.cn00-6.00 sec 114 MBytes 954 Mbits/sec 82344
[ 5] 6.00-7.00 sec 114 MBytes 954 Mbits/sec 82344
[ 5] 7.00-8.00 sec 114 MBytes 954 Mbits/sec 82344
[ 5] 8.00-9.00 sec 114 MBytes 954 Mbits/sec 82344
[ 5] 9.00-10.00 sec 114 MBytes 954 Mbits/sec 82344
– – – – – – – – – – – – – – – – – – – – – – – – –
[ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
[ 5] 0.00-10.00 sec 1.11 GBytes 954 Mbits/sec 0.000 ms 0/823440 (0%) sender
[ 5] 0.00-10.00 sec 1.11 GBytes 954 Mbits/sec 0.000 ms 0/823440 (0%) receiver
iperf Done.
# 指定测试时间
$ iperf3 -c 192.168.1.100 -t 30
# 指定窗口大小
$ iperf3 -c 192.168.1.100 -w 1M
# 指定MTU大小
$ iperf3 -c 192.168.1.100 -M 9000
Part04-netperf使用
4.1 netperf测试
$ sudo dnf install -y netperf
Last metadata expiration check: 0:45:23 ago on Thu 03 Apr 2026 19:10:15 AM CST.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
netperf x86_64 2.7.0-20.el10 epel 234 k
Transaction Summary
================================================================================
Install 1 Packages
Total download size: 234 k
Installed size: 567 k
Complete!
# 启动netserver
$ netserver
Starting netserver with host ‘IN(6)ADDR_ANY’ port ‘12865’ and family AF_UNSPEC
# TCP_STREAM测试
$ netperf -H 192.168.1.100
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.1.100 () port 0 AF_INET
Recv Send Send
Socket Socket Message Elapsed
Size Size Size Time Throughput
bytes bytes bytes secs. 10^6bits/sec
87380 16384 16384 10.01 941.23
# UDP_STREAM测试
$ netperf -H 192.168.1.100 -t UDP_STREAM
MIGRATED UDP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.1.100 () port 0 AF_INET
Socket Message Elapsed Messages
Size Size Time Okay Errors Throughput
bytes bytes secs # # 10^6bits/sec
212992 65507 10.00 181770 0 954.20
87380 10.00 181770 954.20
# TCP_RR测试(请求响应)
$ netperf -H 192.168.1.100 -t TCP_RR
MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.1.100 () port 0 AF_INET
Local /Remote
Socket Size Request Resp. Elapsed Trans.
Send Recv Size Size Time Rate
bytes Bytes bytes bytes secs. per sec
16384 87380 1 1 10.00 14523.45
16384 87380
# TCP_CRR测试(连接请求响应)
$ netperf -H 192.168.1.100 -t TCP_CRR
MIGRATED TCP Connect/Request/Response TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.1.100 () port 0 AF_INET
Local /Remote
Socket Size Request Resp. Elapsed Trans.
Send Recv Size Size Time Rate
bytes Bytes bytes bytes secs. per sec
16384 87380 1 1 10.00 5234.56
16384 87380
Part05-性能测试实战
5.1 网络性能评估
$ cat > /usr/local/bin/network_test.sh << 'EOF' #!/bin/bash SERVER="192.168.1.100" LOG_FILE="/var/log/network_test.log" echo "=== Network Performance Test ===" | tee -a $LOG_FILE echo "Date: $(date)" | tee -a $LOG_FILE # TCP带宽测试 echo -e "\n[TCP Bandwidth Test]" | tee -a $LOG_FILE iperf3 -c $SERVER -t 60 | tee -a $LOG_FILE # UDP带宽测试 echo -e "\n[UDP Bandwidth Test]" | tee -a $LOG_FILE iperf3 -c $SERVER -u -b 1G -t 60 | tee -a $LOG_FILE # 多线程测试 echo -e "\n[Multi-thread Test]" | tee -a $LOG_FILE iperf3 -c $SERVER -P 4 -t 60 | tee -a $LOG_FILE # 请求响应测试 echo -e "\n[Request/Response Test]" | tee -a $LOG_FILE netperf -H $SERVER -t TCP_RR -l 60 | tee -a $LOG_FILE echo -e "\n=== Test Completed ===" | tee -a $LOG_FILE EOF chmod +x /usr/local/bin/network_test.sh # 执行测试 $ sudo /usr/local/bin/network_test.sh === Network Performance Test === Date: Thu Apr 3 19:15:00 CST 2026 [TCP Bandwidth Test] Connecting to host 192.168.1.100, port 520学习交流加群风哥微信: itpux-com1 [ 5] local 192.168.1.10 port 54329 connected to 192.168.1.100 port 5201 [ ID] Interval Transfer Bitrate Retr Cwnd [ 5] 0.00-60.00 sec 6.59 GBytes 941 Mbits/sec 0 390 KBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bitrate Retr [ 5] 0.00-60.00 sec 6.59 GBytes 941 Mbits/sec 0 sender [ 5] 0.00-60.00 sec 6.59 GBytes 941 Mbits/sec receiver iperf Done. [UDP Bandwidth Test] ...
1. 测试前确保网络环境稳定
2. 使用多种测试方法综合评估
3. 长时间测试获得准确结果
4. 记录测试结果用于对比
5. 注意测试对生产环境的影响
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
