hana_shinのLinux技術ブログ

Linuxの技術情報を掲載しています。特にネットワークをメインに掲載していきます。

iperf3コマンドの使い方



1 iperf3コマンドとは?

利用可能なネットワークの最大帯域の測定や、指定した帯域の負荷をかけるためのものです。

2 検証環境

2.1 ネットワーク構成

サーバとクライアントの2台構成です。図中のens33はNICの名前です。IPv4アドレスの他に、IPv6リンクローカルアドレスも記載しています。

                               192.168.2.0/24
client(ens33) ------------------------------------------(ens33) server
        .105                                           .100
fe80::3e2:a9c0:9fa6:a8ad/64                            fe80::174:936a:8876:8055/64

2.2 版数

CentOS版数は、サーバ、クライアントともに下記版数です。

[root@server ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

カーネル版数は以下のとおりです。

[root@server ~]# uname  -r
3.10.0-1160.el7.x86_64

3 インストール方法

サーバとクライアントでiperf3パッケージをインストールします。

[root@server ~]#  yum -y install iperf3

iperf3コマンドの版数を確認します。

[root@server ~]# iperf3 -v
iperf 3.1.7
Linux server 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
Optional features available: CPU affinity setting, IPv6 flow label, TCP congestion algorithm setting, sendfile / zerocopy, socket pacing

4 事前準備

サーバでポート番号を開放します。iperf3は,TCP/UDPの5201番ポートを使うので、5201番ポートへのアクセスを許可しておきます。まず、TCPの5201番ポートを開放します。firewall-cmdの使い方は、firewall-cmdの使い方 - hana_shinのLinux技術ブログを参照してください。

[root@server ~]# firewall-cmd --add-port=5201/tcp
success

ポートの状態を確認します。TCPの5201番ポートが開放されたことがわかります。

[root@server ~]# firewall-cmd --list-ports
5201/tcp

次に、UDPの5201番ポートを開放します。

[root@server ~]# firewall-cmd --add-port=5201/udp
success

ポートの状態を確認します。UDPの5201番ポートが開放されたことがわかります。

[root@server ~]# firewall-cmd --list-ports
5201/tcp 5201/udp

5 オプション一覧

オプション一覧を確認します。

[root@server ~]# iperf3 -h
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
  --forceflush              force flushing output at every interval
  -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)
  --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, --len       #[KMG]    length of buffer to read or write
                            (default 128 KB for TCP, dynamic or 1 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

[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

6 利用可能な最大帯域を測定する方法(もっとも基本的な使い方)

クライアントからサーバにTCPパケットを送信して帯域を測定します。

サーバでiperf3コマンドを実行します。このとき、-sオプションを指定します。

[root@server ~]# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

クライアントでiperf3コマンドを実行します。このとき、-cオプションを指定します。サーバのIPアドレスには192.168.0.10を指定します。測定した送信側、受信側の帯域が1.56Gbits/secであることがわかります。

[root@client ~]# iperf3 -c 192.168.2.100
Connecting to host 192.168.2.100, port 5201
[  4] local 192.168.2.105 port 51136 connected to 192.168.2.100 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   149 MBytes  1.25 Gbits/sec    0   1.18 MBytes
[  4]   1.00-2.00   sec   175 MBytes  1.47 Gbits/sec    9   1.44 MBytes
[  4]   2.00-3.00   sec   181 MBytes  1.52 Gbits/sec    0   1.57 MBytes
[  4]   3.00-4.00   sec   188 MBytes  1.57 Gbits/sec    0   1.68 MBytes
[  4]   4.00-5.00   sec   181 MBytes  1.52 Gbits/sec    0   1.76 MBytes
[  4]   5.00-6.00   sec   171 MBytes  1.44 Gbits/sec    0   1.82 MBytes
[  4]   6.00-7.00   sec   182 MBytes  1.53 Gbits/sec    4   1.37 MBytes
[  4]   7.00-8.00   sec   205 MBytes  1.72 Gbits/sec    0   1.46 MBytes
[  4]   8.00-9.00   sec   208 MBytes  1.74 Gbits/sec    0   1.54 MBytes
[  4]   9.00-10.00  sec   218 MBytes  1.82 Gbits/sec    0   1.61 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  1.81 GBytes  1.56 Gbits/sec   13             sender
[  4]   0.00-10.00  sec  1.81 GBytes  1.56 Gbits/sec                  receiver

iperf Done.

サーバの実行結果は以下のとおりです。受信側の帯域が1.55Gbits/secであることがわかります。

[root@server ~]# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 192.168.2.105, port 51134
[  5] local 192.168.2.100 port 5201 connected to 192.168.2.105 port 51136
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec   142 MBytes  1.19 Gbits/sec
[  5]   1.00-2.00   sec   173 MBytes  1.45 Gbits/sec
[  5]   2.00-3.00   sec   182 MBytes  1.53 Gbits/sec
[  5]   3.00-4.00   sec   187 MBytes  1.57 Gbits/sec
[  5]   4.00-5.00   sec   181 MBytes  1.52 Gbits/sec
[  5]   5.00-6.00   sec   170 MBytes  1.43 Gbits/sec
[  5]   6.00-7.00   sec   184 MBytes  1.54 Gbits/sec
[  5]   7.00-8.00   sec   204 MBytes  1.71 Gbits/sec
[  5]   8.00-9.00   sec   208 MBytes  1.75 Gbits/sec
[  5]   9.00-10.01  sec   217 MBytes  1.81 Gbits/sec
[  5]  10.01-10.04  sec  8.56 MBytes  2.00 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-10.04  sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-10.04  sec  1.81 GBytes  1.55 Gbits/sec                  receiver
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

7 実行時間を指定する方法(-t)

帯域測定の時間はデフォルトで10秒です。-tオプションを使うことで、測定時間を変更することができます。ここでは、5秒間実行してみます。サーバでiperf3コマンドを実行します。このとき、-sオプションを指定します。

[root@server ~]# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

クライアントでiperf3コマンドを実行します。このとき、-tオプションを指定して測定時間を指定します。ここでは5秒間帯域の測定をしてみます。

[root@client ~]# iperf3 -c 192.168.2.100 -t 5
Connecting to host 192.168.2.100, port 5201
[  4] local 192.168.2.105 port 51140 connected to 192.168.2.100 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   163 MBytes  1.37 Gbits/sec    0   1.59 MBytes
[  4]   1.00-2.00   sec   168 MBytes  1.41 Gbits/sec   45   1.48 MBytes
[  4]   2.00-3.00   sec   161 MBytes  1.35 Gbits/sec    0   1.61 MBytes
[  4]   3.00-4.00   sec   215 MBytes  1.80 Gbits/sec    0   1.71 MBytes
[  4]   4.00-5.01   sec   215 MBytes  1.80 Gbits/sec    0   1.78 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-5.01   sec   922 MBytes  1.54 Gbits/sec   45             sender
[  4]   0.00-5.01   sec   919 MBytes  1.54 Gbits/sec                  receiver

iperf Done.

サーバでiperf3コマンドの実行結果を確認します。最終結果に"0.00-5.05"と表示されているため、帯域の測定時間が5秒であることがわかります。

[root@server ~]# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 192.168.2.105, port 51138
[  5] local 192.168.2.100 port 5201 connected to 192.168.2.105 port 51140
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec   154 MBytes  1.29 Gbits/sec
[  5]   1.00-2.00   sec   168 MBytes  1.41 Gbits/sec
[  5]   2.00-3.00   sec   161 MBytes  1.35 Gbits/sec
[  5]   3.00-4.00   sec   215 MBytes  1.80 Gbits/sec
[  5]   4.00-5.00   sec   214 MBytes  1.80 Gbits/sec
[  5]   5.00-5.05   sec  8.27 MBytes  1.49 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-5.05   sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-5.05   sec   919 MBytes  1.53 Gbits/sec                  receiver

8 帯域を指定する方法(-b)

このオプションは、利用可能な最大帯域を測定する、という目的に使うのではなく、指定した帯域の負荷をかけた状態で他の様々なテストを行うときに使うものです。
サーバの実行方法は、これまでの方法と同じなので、ここでは省略します。クライアントの実行結果のみを記載します。

8.1 100(Mbits/sec)を指定した場合

クライアントの実行結果を確認します。送信側、受信側の最大帯域が99.1Mbits/secであることがわかります。

[root@client ~]# iperf3 -c 192.168.2.100 -b 100M
Connecting to host 192.168.2.100, port 5201
[  4] local 192.168.2.105 port 51144 connected to 192.168.2.100 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  11.0 MBytes  91.7 Mbits/sec    0    140 KBytes
[  4]   1.00-2.00   sec  11.9 MBytes  99.8 Mbits/sec    0    195 KBytes
[  4]   2.00-3.00   sec  11.9 MBytes  99.6 Mbits/sec    0    257 KBytes
[  4]   3.00-4.00   sec  11.9 MBytes  99.5 Mbits/sec    0    294 KBytes
[  4]   4.00-5.00   sec  12.0 MBytes   101 Mbits/sec    0    331 KBytes
[  4]   5.00-6.00   sec  11.9 MBytes  99.8 Mbits/sec    0    365 KBytes
[  4]   6.00-7.00   sec  11.9 MBytes  99.3 Mbits/sec    0    393 KBytes
[  4]   7.00-8.00   sec  12.0 MBytes   101 Mbits/sec    0    417 KBytes
[  4]   8.00-9.00   sec  11.9 MBytes  99.5 Mbits/sec    0    428 KBytes
[  4]   9.00-10.00  sec  12.0 MBytes   101 Mbits/sec    0    441 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec   118 MBytes  99.1 Mbits/sec    0             sender
[  4]   0.00-10.00  sec   118 MBytes  99.1 Mbits/sec                  receiver

iperf Done.

8.2 50(Mbits/sec)を指定した場合

クライアントの実行結果を確認します。送信側、受信側の最大帯域が49.6Mbits/sec であることがわかります。

[root@client ~]# iperf3 -c 192.168.2.100 -b 50M
Connecting to host 192.168.2.100, port 5201
[  4] local 192.168.2.105 port 51148 connected to 192.168.2.100 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  5.51 MBytes  46.2 Mbits/sec    0   93.3 KBytes
[  4]   1.00-2.00   sec  5.88 MBytes  49.2 Mbits/sec    0    126 KBytes
[  4]   2.00-3.00   sec  6.00 MBytes  50.4 Mbits/sec    0    146 KBytes
[  4]   3.00-4.00   sec  6.00 MBytes  50.2 Mbits/sec    0    165 KBytes
[  4]   4.00-5.00   sec  5.88 MBytes  49.3 Mbits/sec    0    185 KBytes
[  4]   5.00-6.00   sec  6.00 MBytes  50.3 Mbits/sec    0    201 KBytes
[  4]   6.00-7.00   sec  6.00 MBytes  50.3 Mbits/sec    0    226 KBytes
[  4]   7.00-8.00   sec  5.88 MBytes  49.3 Mbits/sec    0    245 KBytes
[  4]   8.00-9.00   sec  6.00 MBytes  50.4 Mbits/sec    0    255 KBytes
[  4]   9.00-10.00  sec  6.00 MBytes  50.2 Mbits/sec    0    263 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  59.1 MBytes  49.6 Mbits/sec    0             sender
[  4]   0.00-10.00  sec  59.1 MBytes  49.6 Mbits/sec                  receiver

iperf Done.

9 測定に使用するインタフェースを指定する方法(-B)

複数のインタフェースがある場合に使用するオプションです。-Bオプションで指定したインタフェースから帯域測定用のパケットを送信するようになります。このオプションは、サーバとクライアントで使うことができます。私の検証環境ではサーバ、クライアントともにインタフェースが1つしかないので、あまり意味はありませんが、使い方を説明するため、それぞれのインタフェースを指定してみます。

サーバでiperf3コマンドを実行します。このとき、-Bオプションを指定してサーバのインタフェースを指定します。

[root@server ~]# iperf3 -s -B 192.168.2.100
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

クライアントでiperf3コマンドを実行します。このとき、-Bオプションを指定してクライアントのインタフェースを指定します。

[root@client ~]# iperf3 -c 192.168.2.100 -B 192.168.2.105
Connecting to host 192.168.2.100, port 5201
[  4] local 192.168.2.105 port 44045 connected to 192.168.2.100 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   175 MBytes  1.46 Gbits/sec    0    814 KBytes
[  4]   1.00-2.00   sec   170 MBytes  1.43 Gbits/sec   26   1.38 MBytes
[  4]   2.00-3.00   sec   186 MBytes  1.56 Gbits/sec    0   1.52 MBytes
[  4]   3.00-4.00   sec   184 MBytes  1.54 Gbits/sec    0   1.64 MBytes
[  4]   4.00-5.00   sec   199 MBytes  1.67 Gbits/sec    0   1.73 MBytes
[  4]   5.00-6.00   sec   214 MBytes  1.79 Gbits/sec    0   1.80 MBytes
[  4]   6.00-7.00   sec   218 MBytes  1.83 Gbits/sec    0   1.85 MBytes
[  4]   7.00-8.01   sec   211 MBytes  1.76 Gbits/sec   11   1.37 MBytes
[  4]   8.01-9.00   sec   216 MBytes  1.82 Gbits/sec    0   1.47 MBytes
[  4]   9.00-10.00  sec   219 MBytes  1.84 Gbits/sec    0   1.55 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  1.94 GBytes  1.67 Gbits/sec   37             sender
[  4]   0.00-10.00  sec  1.94 GBytes  1.67 Gbits/sec                  receiver

iperf Done.

10 ポート番号を指定する方法(-p)

iperf3はデフォルトで5201番のポートを使います。すでに他のアプリが5201を使っている場合、5201以外のポート番号を使う必要があります。このような時に使用するオプションです。ここでは、5201番ポートではなく11111番ポートを使うため、TCPの11111番ポートを開放します。UDPを使って帯域測定する場合は、UDPの11111番ポートも開放してください。

[root@server ~]# firewall-cmd --add-port=11111/tcp
success

ポートの状態を確認します。TCPの11111番ポートが開放されたことがわかります。

[root@server ~]# firewall-cmd --list-ports
5201/tcp 5201/udp 11111/tcp

サーバでiperf3を実行します。このとき、-pオプションを指定して、iperf3がTCPの11111番ポートでListenするようにします。

[root@server ~]# iperf3 -s -p 11111
-----------------------------------------------------------
Server listening on 11111
-----------------------------------------------------------

もう1つターミナルを開きます。lsofコマンドを実行して、iperf3がListenしているポート番号を確認します。iperf3がTCPの11111番ポートでListenしていることがわかります。
なお、lsofコマンドの使い方は、
lsofコマンドの使い方 - hana_shinのLinux技術ブログを参照してください。

[root@server ~]# lsof -c iperf3 -a -i -a -P
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
iperf3  5392 root    3u  IPv6  73032      0t0  TCP *:11111 (LISTEN)

クライアントでiperf3コマンドを実行します。このとき、-pオプションを指定してサーバのiperf3がListenしているポート番号を指定します。

[root@client ~]# iperf3 -c 192.168.2.100 -p 11111
Connecting to host 192.168.2.100, port 11111
[  4] local 192.168.2.105 port 39192 connected to 192.168.2.100 port 11111
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   145 MBytes  1.22 Gbits/sec    0    663 KBytes
[  4]   1.00-2.00   sec   191 MBytes  1.61 Gbits/sec    0   1.04 MBytes
[  4]   2.00-3.00   sec   192 MBytes  1.62 Gbits/sec   22   1.35 MBytes
[  4]   3.00-4.01   sec   178 MBytes  1.48 Gbits/sec    0   1.50 MBytes
[  4]   4.01-5.01   sec   189 MBytes  1.58 Gbits/sec    0   1.61 MBytes
[  4]   5.01-6.00   sec   216 MBytes  1.82 Gbits/sec    0   1.70 MBytes
[  4]   6.00-7.01   sec   208 MBytes  1.73 Gbits/sec    0   1.76 MBytes
[  4]   7.01-8.01   sec   219 MBytes  1.84 Gbits/sec    0   1.81 MBytes
[  4]   8.01-9.01   sec   221 MBytes  1.86 Gbits/sec    0   1.85 MBytes
[  4]   9.01-10.00  sec   216 MBytes  1.82 Gbits/sec    0   1.87 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  1.93 GBytes  1.66 Gbits/sec   22             sender
[  4]   0.00-10.00  sec  1.93 GBytes  1.65 Gbits/sec                  receiver

iperf Done.

11 指定したCPUでiperf3を実行する方法(-A)

iperf3を実行するCPUを指定するオプションです。このオプションは、サーバとクライアントで使うことができます。ここでは、サーバでiperf3を指定したCPUで動作させる実行例を示します。まず、サーバに搭載れているCPUを確認します。4つのCPUが搭載されていることがわかります。

[root@server ~]# cat /proc/cpuinfo |grep processor
processor       : 0
processor       : 1
processor       : 2
processor       : 3

iperf3をCPU0で動作させてみます。

[root@server ~]# iperf3 -s -A 0
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

psコマンドを実行して、iperf3が動作しているCPUを確認します。iperf3がCPU0で動作していることがわかります。なお、psコマンドの使い方は、psコマンドの使い方 - hana_shinのLinux技術ブログを参照してください。

[root@server ~]# ps -C iperf3 -o comm,pid,psr
COMMAND            PID PSR
iperf3            5596   0

次にiperf3をCPU3で動作させてみます。

[root@server ~]#  iperf3 -s -A 3
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

psコマンドを実行して、iperf3が動作しているCPUを確認します。iperf3がCPU3で動作していることがわかります。

[root@server ~]# ps -C iperf3 -o comm,pid,psr
COMMAND            PID PSR
iperf3            5632   3

12 UDPを使う方法(-u)

帯域測定用のパケットにTCPではなくUDPを使う場合に指定するオプションです。サーバでiperf3コマンドを実行します。サーバ側はTCPでもUDPでもオプションに違いはありません。

12.1 デフォルトのビットレートで送信する方法

サーバでiperf3を実行します。

[root@server ~]#  iperf3 -s

クライアントでiperf3を実行します。このとき"-u"オプションを指定して、UDPパケットを送信してみます。デフォルトでは、1Mbits/secでUDPパケットを送信します。

[root@client ~]# iperf3 -c 192.168.2.100 -u
Connecting to host 192.168.2.100, port 5201
[  4] local 192.168.2.105 port 45835 connected to 192.168.2.100 port 5201
[ ID] Interval           Transfer     Bandwidth       Total Datagrams
[  4]   0.00-1.00   sec   116 KBytes   950 Kbits/sec  82
[  4]   1.00-2.00   sec   129 KBytes  1.05 Mbits/sec  91
[  4]   2.00-3.00   sec   127 KBytes  1.04 Mbits/sec  90
[  4]   3.00-4.00   sec   129 KBytes  1.06 Mbits/sec  91
[  4]   4.00-5.00   sec   127 KBytes  1.04 Mbits/sec  90
[  4]   5.00-6.00   sec   129 KBytes  1.06 Mbits/sec  91
[  4]   6.00-7.00   sec   127 KBytes  1.04 Mbits/sec  90
[  4]   7.00-8.00   sec   129 KBytes  1.05 Mbits/sec  91
[  4]   8.00-9.00   sec   129 KBytes  1.05 Mbits/sec  91
[  4]   9.00-10.00  sec   127 KBytes  1.04 Mbits/sec  90
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-10.00  sec  1.24 MBytes  1.04 Mbits/sec  0.137 ms  0/897 (0%)
[  4] Sent 897 datagrams

iperf Done.

12.2 ビットレートを指定する方法(-b)

"-b"を指定すると、UDPの送信ビットレートを指定することができます。ここでは、5Mbit/sでUDPパケットを送信してみます。

[root@client ~]# iperf3 -c 192.168.2.100 -u -b 5M
Connecting to host 192.168.2.100, port 5201
[  4] local 192.168.2.105 port 41786 connected to 192.168.2.100 port 5201
[ ID] Interval           Transfer     Bandwidth       Total Datagrams
[  4]   0.00-1.00   sec   560 KBytes  4.57 Mbits/sec  396
[  4]   1.00-2.00   sec   604 KBytes  4.95 Mbits/sec  427
[  4]   2.00-3.00   sec   611 KBytes  5.01 Mbits/sec  432
[  4]   3.00-4.00   sec   609 KBytes  4.99 Mbits/sec  431
[  4]   4.00-5.00   sec   611 KBytes  5.01 Mbits/sec  432
[  4]   5.00-6.00   sec   609 KBytes  4.98 Mbits/sec  431
[  4]   6.00-7.00   sec   612 KBytes  5.01 Mbits/sec  433
[  4]   7.00-8.00   sec   609 KBytes  5.00 Mbits/sec  431
[  4]   8.00-9.00   sec   611 KBytes  5.00 Mbits/sec  432
[  4]   9.00-10.00  sec   608 KBytes  4.98 Mbits/sec  430
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-10.00  sec  5.90 MBytes  4.95 Mbits/sec  0.090 ms  0/4275 (0%)
[  4] Sent 4275 datagrams

iperf Done.

13 データ送受信用コネクションを複数生成する方法(-P)

iperf3は、デフォルトで以下のTCPコネクションを生成します。
・制御用×1本(帯域測定にTCPを使うかUDPを使うか等の情報交換で使用する)
・帯域測定用×1本
"-P"オプションは帯域測定用のTCPコネクション数を指定します。ここでは、帯域測定用のTCPコネクションを3つ作成してみます。

サーバでiperf3コマンドを実行します。

[root@server ~]#  iperf3 -s

クライアントでiperf3コマンドを実行します。-Pオプションを指定して帯域測定用のTCPコネクションを3つ生成してみます。実行結果(★)より、TCPコネクションが3つ確立されていることがわかります。

[root@client ~]# iperf3 -c 192.168.2.100 -P 3
Connecting to host 192.168.2.100, port 5201
[  4] local 192.168.2.105 port 51172 connected to 192.168.2.100 port 5201 ★
[  6] local 192.168.2.105 port 51174 connected to 192.168.2.100 port 5201 ★
[  8] local 192.168.2.105 port 51176 connected to 192.168.2.100 port 5201 ★
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  69.9 MBytes   586 Mbits/sec    0    553 KBytes
[  6]   0.00-1.00   sec  56.7 MBytes   476 Mbits/sec    0    477 KBytes
[  8]   0.00-1.00   sec  46.1 MBytes   386 Mbits/sec    0    411 KBytes
[SUM]   0.00-1.00   sec   173 MBytes  1.45 Gbits/sec    0
-snip-
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec   830 MBytes   696 Mbits/sec  125             sender
[  4]   0.00-10.00  sec   826 MBytes   693 Mbits/sec                  receiver
[  6]   0.00-10.00  sec   690 MBytes   579 Mbits/sec  109             sender
[  6]   0.00-10.00  sec   687 MBytes   576 Mbits/sec                  receiver
[  8]   0.00-10.00  sec   446 MBytes   374 Mbits/sec  120             sender
[  8]   0.00-10.00  sec   443 MBytes   372 Mbits/sec                  receiver
[SUM]   0.00-10.00  sec  1.92 GBytes  1.65 Gbits/sec  354             sender
[SUM]   0.00-10.00  sec  1.91 GBytes  1.64 Gbits/sec                  receiver

iperf Done.

14 IPv6で帯域測定をする方法(-6)

サーバでiperf3コマンドを実行します。このとき、-6オプションを指定してIPv6アドレスを使うことを指定します。

[[root@server ~]# iperf3 -s -6
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

クライアントでiperf3コマンドを実行します。インタフェース名は、帯域測定用のIPv6パケットを送信するインタフェースの名前です。<宛先のIPv6アドレス>%<インタフェース名>

[root@client ~]# iperf3 -6 -c fe80::174:936a:8876:8055%ens33
Connecting to host fe80::174:936a:8876:8055%ens33, port 5201
[  4] local fe80::3e2:a9c0:9fa6:a8ad port 48898 connected to fe80::174:936a:8876:8055 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  95.7 MBytes   802 Mbits/sec    0    551 KBytes
[  4]   1.00-2.00   sec   131 MBytes  1.10 Gbits/sec    0    651 KBytes
[  4]   2.00-3.00   sec   158 MBytes  1.33 Gbits/sec    0    747 KBytes
[  4]   3.00-4.00   sec   173 MBytes  1.45 Gbits/sec    0   1.10 MBytes
[  4]   4.00-5.00   sec   173 MBytes  1.45 Gbits/sec    0   1.53 MBytes
[  4]   5.00-6.00   sec   175 MBytes  1.47 Gbits/sec    0   1.54 MBytes
[  4]   6.00-7.00   sec   176 MBytes  1.48 Gbits/sec    0   1.54 MBytes
[  4]   7.00-8.00   sec   176 MBytes  1.48 Gbits/sec    0   1.54 MBytes
[  4]   8.00-9.00   sec   176 MBytes  1.48 Gbits/sec    0   1.54 MBytes
[  4]   9.00-10.00  sec   176 MBytes  1.48 Gbits/sec    0   1.54 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  1.57 GBytes  1.35 Gbits/sec    0             sender
[  4]   0.00-10.00  sec  1.57 GBytes  1.35 Gbits/sec                  receiver

iperf Done.

15 ファイル転送のボトルネックを調べる方法(-F)

  • "-F"オプションを指定しないと、クライアントのiperf3が送信したデータはサーバのiperf3で受信され、ストレージに書き込まず、廃棄されます。
  • "-F"オプションを指定すると、サーバのiperf3は受信したデータをストレージに書き込みます。

問題が発生しているシステムで、"-F"オプションを指定した場合と指定しない場合の実行結果を比較して、ストレージにボトルネックがあるかどうか絞り込みます。なお、manによると、送信したファイルサイズが元のファイルサイズと一致しない場合があるようです。

テスト用のファイルを作成します。
なお、ファイルの作成方法は、ファイルの作り方 - hana_shinのLinux技術ブログを参照してください。

[root@client ~]# fallocate -l 500M test.dat

作成したファイルのファイルサイズを確認します。

[root@client ~]# ls -lh test.dat
-rw-r--r--. 1 root root 500M  1月 16 11:10 test.dat

サーバでiperf3コマンドを実行します。このとき、-Fオプションを指定して受信したデータを書き込むファイルを指定します。

[root@server ~]# iperf3 -s -F test.dat
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

クライアントでiperf3コマンドを実行します。このとき、-Fオプションを指定して送信するファイルを指定します。

[root@client ~]# iperf3 -c 192.168.2.100 -F test.dat
Connecting to host 192.168.2.100, port 5201
[  4] local 192.168.2.105 port 46566 connected to 192.168.2.100 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  75.1 MBytes   630 Mbits/sec    0    212 KBytes
[  4]   1.00-2.00   sec   101 MBytes   847 Mbits/sec    0    298 KBytes
[  4]   2.00-2.43   sec  54.4 MBytes  1.05 Gbits/sec    0    328 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-2.43   sec   230 MBytes   794 Mbits/sec    0             sender
        Sent  230 MByte /  500 MByte (46%) of test.dat
[  4]   0.00-2.43   sec   227 MBytes   784 Mbits/sec                  receiver

iperf Done.

なお、サーバでstraceコマンドを使うと、iperf3が受信データをファイルに書き込んでいることがわかります。straceコマンドの使いかたは、straceコマンドの使い方 - hana_shinのLinux技術ブログを参照してください。

[root@server ~]# strace -e trace=open iperf3 -s -F test.dat
-snip-
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 5
Accepted connection from 192.168.2.105, port 46580
open("/tmp/iperf3.xTHBO9", O_RDWR|O_CREAT|O_EXCL, 0600) = 6
open("test.dat", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 7
-snip-

16 詳細情報を表示する方法(-V)

このオプションは、サーバ、クライアントの両方で使用できます。Vオプションを指定すると、iperf3の版数、OS版数、実行時刻等の詳細情報が追加表示されます。

[root@server ~]# iperf3 -s -V
iperf 3.1.7
Linux server 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Time: Sat, 15 Jan 2022 12:50:06 GMT
Accepted connection from 192.168.2.105, port 51194
      Cookie: client.1642251006.468534.06949ef12fc
      TCP MSS: 0 (default)
-snip-
[root@client ~]# iperf3 -c 192.168.2.100 -V
iperf 3.1.7
Linux client 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
Control connection MSS 1448
Time: Sat, 15 Jan 2022 12:50:06 GMT
Connecting to host 192.168.2.100, port 5201
      Cookie: client.1642251006.468534.06949ef12fc
      TCP MSS: 1448 (default)
-snip-

17 タイトルを付ける方法(-T)

表示されるレポートの各行の行頭に文字列を表示することができます。ここではホスト名を表示してみます。

[root@server ~]# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

hostnameコマンドの実行結果(client)が左端に表示されていることがわかります。

[root@client ~]# iperf3 -c 192.168.2.100 -T `hostname`
client:  Connecting to host 192.168.2.100, port 5201
client:  [  4] local 192.168.2.105 port 51200 connected to 192.168.2.100 port 5201
client:  [ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
client:  [  4]   0.00-1.00   sec   148 MBytes  1.24 Gbits/sec    0   1.33 MBytes
client:  [  4]   1.00-2.00   sec   185 MBytes  1.55 Gbits/sec   10   1.42 MBytes
client:  [  4]   2.00-3.00   sec   191 MBytes  1.61 Gbits/sec    0   1.55 MBytes
client:  [  4]   3.00-4.00   sec   200 MBytes  1.68 Gbits/sec    0   1.66 MBytes
client:  [  4]   4.00-5.00   sec   200 MBytes  1.68 Gbits/sec    0   1.74 MBytes
client:  [  4]   5.00-6.00   sec   214 MBytes  1.80 Gbits/sec    0   1.80 MBytes
client:  [  4]   6.00-7.00   sec   209 MBytes  1.75 Gbits/sec    0   1.84 MBytes
client:  [  4]   7.00-8.00   sec   220 MBytes  1.85 Gbits/sec    0   1.87 MBytes
client:  [  4]   8.00-9.00   sec   192 MBytes  1.61 Gbits/sec   19   1.37 MBytes
client:  [  4]   9.00-10.01  sec   221 MBytes  1.85 Gbits/sec    0   1.47 MBytes
client:  - - - - - - - - - - - - - - - - - - - - - - - - -
client:  [ ID] Interval           Transfer     Bandwidth       Retr
client:  [  4]   0.00-10.01  sec  1.93 GBytes  1.66 Gbits/sec   29             sender
client:  [  4]   0.00-10.01  sec  1.93 GBytes  1.66 Gbits/sec                  receiver
client:
client:  iperf Done.

Z 参考情報

私が業務や記事執筆で参考にした書籍を以下のページに記載します。
Linux技術のスキルアップをしよう! - hana_shinのLinux技術ブログ