带宽测试工具iperf的安装与使用

  1. iperf工具介绍
  2. iperf工具安装
  3. iperf工具使用
    1. 1. 启动服务端
    2. 2. 启动客户端
    3. 3.查看测试结果
  4. iperf常用选项
    1. 通用选项
    2. 服务端选项
    3. 客户端选项

iperf工具介绍

Iperf 是常用的网络测试工具,可以创建 TCP 和 UDP 数据流并测量承载它们的网络的吞吐量。

Iperf 允许用户设置可用于测试网络,或者用于优化或调整网络的各种参数。Iperf 具有客户端和服务器功能,可以单向或双向测量两端之间的吞吐量。它是开源软件,可在 Linux、Unix 和 Windows 等各种平台上运行。

iperf工具安装

在客户端和服务端分别安装iperf相同版本,如下:

  1. 根据系统版本,下载对应iperf3 的rpm程序包,下载地址:https://iperf.fr/iperf-download.php

    本示例在操作系统中下载程序包:https://iperf.fr/download/fedora/iperf3-3.1.3-1.fc24.x86_64.rpm

    [root@iZwz9f92w7soch5m251ghgZ ~]# uname -a
    Linux iZwz9f92w7soch5m251ghgZ 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
    [root@iZwz9f92w7soch5m251ghgZ ~]# 
    [root@iZwz9f92w7soch5m251ghgZ ~]# wget https://iperf.fr/download/fedora/iperf3-3.1.3-1.fc24.x86_64.rpm
  2. 安装

    npm -ivh iperf3-3.1.3-1.fc24.x86_64.rpm
  3. 查看iperf版本

    iperf3 -v

iperf工具使用

iperf工具是基于服务器和客户端的工作模式,因此,要使用iperf测试带宽,需要建立一个服务端(用于丢弃流量)和一个客户端(用于产生流量)。

1. 启动服务端

首先在待测服务器A中,启动服务器模式,监听测试数据

iperf3 -s -u

-s 指定工作模式为服务器

默认监听UDP 5001端口

带宽测试通常采用UDP模式 -u,因为能测出极限带宽、时延抖动、丢包率,如果不指定-u,默认测试的是TCP协议的带宽

2. 启动客户端

在与待测服务器A通讯的客户端B中,启动客户端模式发送测试数据

iperf3 -c 192.168.1.1

-c 指定工作模式为客户端,后面跟着的参数为待测服务器A的ip

3.查看测试结果

iperf客户端测试结果如下:

[root@VM-20-11-centos ~]# iperf3 -c 192.168.1.1 
Connecting to host 192.168.1.1, port 5201
[  4] local 10.0.20.11 port 58658 connected to 192.168.1.1 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  4.75 MBytes  39.8 Mbits/sec  766   17.9 KBytes       
[  4]   1.00-2.00   sec   951 KBytes  7.79 Mbits/sec  776   23.4 KBytes       
[  4]   2.00-3.00   sec  1015 KBytes  8.32 Mbits/sec  751   15.2 KBytes       
[  4]   3.00-4.00   sec   951 KBytes  7.79 Mbits/sec  127   9.65 KBytes       
[  4]   4.00-5.00   sec  1015 KBytes  8.32 Mbits/sec   24   12.4 KBytes       
[  4]   5.00-6.00   sec   951 KBytes  7.79 Mbits/sec   23   8.27 KBytes       
[  4]   6.00-7.00   sec  1015 KBytes  8.32 Mbits/sec   30   9.65 KBytes       
[  4]   7.00-8.00   sec  1015 KBytes  8.31 Mbits/sec   21   11.0 KBytes       
[  4]   8.00-9.00   sec   951 KBytes  7.79 Mbits/sec   26   11.0 KBytes       
[  4]   9.00-10.00  sec  1015 KBytes  8.32 Mbits/sec   22   9.65 KBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  13.4 MBytes  11.3 Mbits/sec  2566             sender
[  4]   0.00-10.00  sec  10.6 MBytes  8.88 Mbits/sec                  receiver

通过上面的测试结果,我们可以简单认为服务器A192.168.1.1的带宽为8.8Mbits/sec。

iperf常用选项

[root@iZwz9f92w7soch5m251ghgZ ~]# iperf3 --help
Usage: iperf [-s|-c host] [options]
       iperf [-h|--help] [-v|--version]

Server or Client:
  -p, --port      #         server port to listen on/connect to
  -f, --format    [kmgKMG]  format to report: Kbits, Mbits, KBytes, MBytes
  -i, --interval  #         seconds between periodic bandwidth reports
  -F, --file name           xmit/recv the specified file
  -A, --affinity n/n,m      set CPU affinity
  -B, --bind      <host>    bind to a specific interface
  -V, --verbose             more detailed output
  -J, --json                output in JSON format
  --logfile f               send output to a log file
  -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
Client specific:
  -c, --client    <host>    run in client mode, connecting to <host>
  -u, --udp                 use UDP rather than TCP
  -b, --bandwidth #[KMG][/#] target bandwidth in bits/sec (0 for unlimited)
                            (default 1 Mbit/sec for UDP, unlimited for TCP)
                            (optional slash and packet count for burst mode)
  -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, --len       #[KMG]    length of buffer to read or write
                            (default 128 KB for TCP, 8 KB 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)
  -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'
  -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
  --no-fq-socket-pacing     disable fair-queuing based socket pacing
                            (Linux only)

[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

通用选项

选项 说明
-i 在周期性报告带宽之间暂停n秒。如测试时间是10s,则-i指定为2,则每隔2秒报告一次带宽测试情况,则共计报告5次
-p 设置监听或连接的端口,默认是5001
-u 使用UDP协议测试

服务端选项

选项 说明
-s iperf服务器模式
-d 以后台模式运行服务端
-u 使用UDP协议测试

客户端选项

选项 说明
-c 以客户端模式运行iperf,并且连接至服务端主机ServerIP
-t 指定iperf带宽测试时间,默认是10s
-P 指定客户端并发线程数,默认只运行一个线程
-b <n[KM]> 指定客户端通过UDP协议发送数据的带宽(bit/s)。默认是1Mbit/s
-d 双向测试

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。
My Show My Code