How to use iperf3 tool to monitor network bandwidth in Linux

I have already written an article to check the network bandwidth speed using netperf available at below link
How to monitor network bandwidth in Linux using netperf

In this article I will guide you the steps to be used to monitor the available network bandwidth using iperf3.
One advantage here you have with iperf3 that it is a part of the Red Hat Vanilla DVD and you need not download any third party tool.

Below steps are validated on Red Hat Enterprise Linux 7

You can install the iperf3 using yum command assuming you have a valid repository or you can copy the rpm from the Red Hat DVD and install it manually

The latest version of the iperf source code is at https://github.com/esnet/iperf

With the below list of steps the iperf sets a large send and receive buffer size to maximise throughput, and performs a test for 60 seconds which should be long enough to fully exercise a network.

On Server (IP: 10.58.160.101)

# yum install iperf3
OR
# rpm -Uvh /home/deepak/iperf3-3.1.7-2.el7.x86_64.rpm
warning: /home/deepak/iperf3-3.1.7-2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ################################# [100%]
Updating / installing...
   1:iperf3-3.1.7-2.el7     ################################# [100%]
Explanation of the switches used:
 -i, --interval n
       pause n seconds between periodic bandwidth reports; default is 1, use 0 to disable
 -s, --server
       run in server mode
Run the below command on the server
server # iperf3 -i 10 -s
warning: this system does not seem to support IPv6 - trying IPv4
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 10.58.160.103, port 40614
[  5] local 10.58.160.101 port 5201 connected to 10.58.160.103 port 40616
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-10.00  sec  1.27 GBytes  1.09 Gbits/sec
[  5]  10.00-20.00  sec  1.27 GBytes  1.09 Gbits/sec
[  5]  20.00-30.00  sec  1.27 GBytes  1.09 Gbits/sec
[  5]  30.00-40.00  sec  1.27 GBytes  1.09 Gbits/sec
[  5]  40.00-50.00  sec  1.27 GBytes  1.09 Gbits/sec
[  5]  50.00-60.00  sec  1.27 GBytes  1.09 Gbits/sec
[  5]  60.00-60.04  sec  4.78 MBytes  1.04 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-60.04  sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-60.04  sec  7.63 GBytes  1.09 Gbits/sec                  receiver
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 192.169.173.7, port 35190
[  5] local 192.169.173.5 port 5201 connected to 192.169.173.7 port 35192
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-10.00  sec  3.55 GBytes  3.05 Gbits/sec
[  5]  10.00-20.00  sec  3.59 GBytes  3.08 Gbits/sec
[  5]  20.00-30.00  sec  3.59 GBytes  3.08 Gbits/sec
[  5]  30.00-40.00  sec  3.59 GBytes  3.08 Gbits/sec
[  5]  40.00-50.00  sec  3.59 GBytes  3.08 Gbits/sec
[  5]  50.00-60.00  sec  3.59 GBytes  3.08 Gbits/sec
[  5]  60.00-60.04  sec  14.4 MBytes  3.14 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-60.04  sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-60.04  sec  21.5 GBytes  3.07 Gbits/sec                  receiver
-----------------------------------------------------------
Server listening on 5201
By default the server will use TCP port 5201, if you intend to use some other port use "-p" switch
 -p, --port n
        set server port to listen on/connect to to n (default 5201)

On Client (192.169.173.7, 10.58.160.103)

# rpm -Uvh /tmp/iperf3-3.1.7-2.el7.x86_64.rpm
warning: /tmp/iperf3-3.1.7-2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:iperf3-3.1.7-2.el7               ################################# [100%]
Explanation of the switches used:
-i, --interval n
      pause n seconds between periodic bandwidth reports; default is 1, use 0 to disable

-w, --window n[KM]
      window size / socket buffer size (this gets sent to the server and used on that side)

-t, --time n
      time in seconds to transmit for (default 10 secs)

-c, --client host
      run in client mode, connecting to the specified server

Run the below command wherein the IP with -c is the server IP (eth0)
client # iperf3 -i 10 -w 1M -t 60 -c 10.58.160.101
Connecting to host 10.58.160.101, port 5201
[  4] local 10.58.160.103 port 40616 connected to 10.58.160.101 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-10.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
[  4]  10.00-20.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
[  4]  20.00-30.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
[  4]  30.00-40.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
[  4]  40.00-50.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
[  4]  50.00-60.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-60.00  sec  7.63 GBytes  1.09 Gbits/sec    0             sender
[  4]   0.00-60.00  sec  7.63 GBytes  1.09 Gbits/sec                  receiver

iperf Done.
Another attempt using a different interface (eth2)
client # iperf3 -i 10 -w 1M -t 60 -c 192.169.173.5
Connecting to host 192.169.173.5, port 5201
[  4] local 192.169.173.7 port 35192 connected to 192.169.173.5 port 5201

[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-10.00  sec  3.56 GBytes  3.06 Gbits/sec    0   2.10 MBytes
[  4]  10.00-20.00  sec  3.59 GBytes  3.08 Gbits/sec    0   2.10 MBytes
[  4]  20.00-30.00  sec  3.59 GBytes  3.08 Gbits/sec    0   2.10 MBytes
[  4]  30.00-40.00  sec  3.59 GBytes  3.08 Gbits/sec    0   2.10 MBytes
[  4]  40.00-50.00  sec  3.59 GBytes  3.08 Gbits/sec    0   2.10 MBytes
[  4]  50.00-60.00  sec  3.59 GBytes  3.08 Gbits/sec    0   2.10 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-60.00  sec  21.5 GBytes  3.08 Gbits/sec    0             sender
[  4]   0.00-60.00  sec  21.5 GBytes  3.08 Gbits/sec                  receiver

iperf Done.
Lets check the allowed bandwidth speed for each of this interface

The first attempt was done using eth0
# ethtool eth0 | grep Speed
        Speed: 1000Mb/s
The second attempt was done using eth2
# ethtool eth2 | grep Speed
        Speed: 3000Mb/s
So as we see the allowed bandwidth for eth0 was 1 Gb and we had a bandwidth speed of almost 1.09Gb/s

while for the other interface we had an allowed bandwidth of 3 Gb/s wherein the bandwidth throughput reached 3.08 Gb/s

I hope this article was useful.