Cyberithub

15 Useful examples of iperf commands in Linux (How to use iperf in Linux)

In this article, I will take you through 15 Useful examples of iperf commands in Linux. iperf is an open source tool that can be easily installed in Linux. It provides a reliable information about Network Bandwidth and its performance. You can easily check the network latency and other errors using this tool. You can also check many different information using iperf tool from Client as well as from Server Side. We will look into various possible uses of this tool in below examples.

Syntax

iperf -s [options]

iperf -c server [options]

iperf -u -s [options]

iperf -u -c server [options]

15 Useful examples of iperf commands in Linux (How to use iperf in Linux) 1

iperf commands in Linux

Also Read: Install iperf and perform network throughput test in Linux (RedHat/CentOS 7/8) in 5 Easy Steps

Example 1: How to check iperf command version

If you want to check iperf command version then you need to use -v option with iperf commands as shown below. As you can see from below output current iperf command version is 2.0.13

[root@localhost ~]# iperf -v
iperf version 2.0.13 (21 Jan 2019) pthreads

NOTE:

Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.

-v : print version information and quit

Example 2: How to Check Network Performance in Server Mode

If you want to run iperf command in Server mode then you need to use -s option with iperf command as shown below. Also if you want to check transfer bandwidth size in KBytes/sec then you need to use -f option and specify the unit.

[root@localhost ~]# iperf -s -f K
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[ 4] local 192.168.0.100 port 5001 connected with 192.168.0.100 port 54310 (peer 12857.11824.3338-unk)
[ ID] Interval Transfer Bandwidth
[ 4] 0.0-64.9 sec 0.08 KBytes 0.00 KBytes/sec

-s : run in server mode

-f : format to report: adaptive, bits, Bytes, Kbits, Mbits, Gbits, KBytes, MBytes, GBytes

Example 3: How to Check Network Performance in Client mode

If you want to check network performance in Client mode then you need to use -c option with iperf command as shown below. In this example we are trying to connect Server 192.168.0.100 on TCP port 5001 with default TCP window size.

[root@localhost ~]# iperf -c 192.168.0.100
------------------------------------------------------------
Client connecting to 192.168.0.100, TCP port 5001
TCP window size: 4.00 MByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.106 port 54358 connected with 192.168.0.100 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 30.9 GBytes 26.5 Gbits/sec

-c : run in client mode, connecting to host

You can also go to the Server end and verify the response as shown below.

------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[ 4] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 54358
[ ID] Interval Transfer Bandwidth
[ 4] 0.0-10.0 sec 32356224 KBytes 3227989 KBytes/sec

NOTE:

Please note that you need to start the Server first before launching any client connections or else you will get connection refused error.

Example 4: How to Start iperf Server on UDP Port

If you want to start iperf Server on UDP Port instead of starting in default TCP Port then you need to use -u option with iperf command as shown below. In this example we are trying to start iperf in Server mode on default UDP Port 5001 using iperf -s -u command.

[root@localhost ~]# iperf -s -u
------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size: 208 KByte (default)
------------------------------------------------------------

Example 5: How to Send data for N secs in Client Mode

If you want to send data for N secs in Client mode then you need to provide the number of seconds using -t option with iperf command as shown below. In this example we are trying to send data to the Server(192.168.0.100) for 15 seconds in Client mode using iperf -c 192.168.0.100 -t 15 command.

[root@localhost ~]# iperf -c 192.168.0.100 -t 15
------------------------------------------------------------
Client connecting to 192.168.0.100, TCP port 5001
TCP window size: 4.00 MByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.100 port 54364 connected with 192.168.0.100 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-15.0 sec 42.6 GBytes 24.4 Gbits/sec

-t : time in seconds to listen for new traffic connections, receive traffic or transmit traffic

Example 6: How to measure bidirectional bandwidths sequentially

If you want to measure bidirectional bandwidths sequentially then you need to use -r option with iperf command as shown below. In this example we are connecting Server 192.168.0.100 on Port 5001 to perform bidirectional tests sequentially.

[root@localhost ~]# iperf -c 192.168.0.100 -r
------------------------------------------------------------
Client connecting to 192.168.0.100, TCP port 5001
TCP window size: 4.00 MByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.106 port 54370 connected with 192.168.0.100 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 30.2 GBytes 26.0 Gbits/sec

-r : Do a bidirectional test individually – client-to-server, followed by a reversed test, server-to-client

You can also go to the Server end and verify the response as shown below.

------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[ 4] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 54370
[ ID] Interval Transfer Bandwidth
[ 4] 0.0-10.0 sec 31710336 KBytes 3167739 KBytes/sec
------------------------------------------------------------
Client connecting to 192.168.0.100, TCP port 5001
TCP window size: 4096 KByte (default)
------------------------------------------------------------
[ 4] local 192.168.0.106 port 54372 connected with 192.168.0.100 port 5001
[ 5] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 54372

Example 7: How to measure bidirectional bandwidths simultaneously

If you want to measure bidirectional bandwidths simultaneously then you need to use -d option with iperf command as shown below. In this example we are connecting Server 192.168.0.100 on Port 5001 to perform bidirectional tests simultaneously.

[root@localhost ~]# iperf -c 192.168.0.100 -d
bind failed: Address already in use
------------------------------------------------------------
Client connecting to 192.168.0.100, TCP port 5001
TCP window size: 4.00 MByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.100 port 54374 connected with 192.168.0.100 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 14.8 GBytes 12.7 Gbits/sec

-d : Do a bidirectional test simultaneously.

You can also verify the response from Server end as shown below.

------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[ 4] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 54374
------------------------------------------------------------
Client connecting to 192.168.0.100, TCP port 5001
TCP window size: 4096 KByte (default)
------------------------------------------------------------
[ 6] local 192.168.0.106 port 54376 connected with 192.168.0.100 port 5001
[ 5] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 54376
[ ID] Interval Transfer Bandwidth
[ 4] 0.0-10.0 sec 15499264 KBytes 1546299 KBytes/sec
[ 6] 0.0-10.0 sec 15464960 KBytes 1544880 KBytes/sec
[ 5] 0.0-10.0 sec 15464960 KBytes 1541043 KBytes/sec
[SUM] 0.0-10.0 sec 30964224 KBytes 3085504 KBytes/sec

Example 8: How to Change TCP Window Size in Client mode

If you want to change the TCP Window size in Client mode then you need to use -w option with iperf command as shown below. In this example we are trying to connect Server 192.168.0.100 on TCP Port 5001 with TCP window size of 4000.

[root@localhost ~]# iperf -c 192.168.0.100 -w 4000
------------------------------------------------------------
Client connecting to 192.168.0.100, TCP port 5001
TCP window size: 7.81 KByte (WARNING: requested 3.91 KByte)
------------------------------------------------------------
[ 3] local 192.168.0.100 port 54378 connected with 192.168.0.100 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 32.4 MBytes 27.1 Mbits/sec

-w : TCP window size (socket buffer size)

Example 9: How to change TCP Window Size in Server mode

If you want to change TCP Window Size in Server mode then you need to use -w option with -s option as shown below. In this example, we are trying to start Server which listens on Port 5001 with a TCP window size of 4000.

[root@localhost ~]# iperf -s -w 4000
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 7.81 KByte (WARNING: requested 3.91 KByte)
------------------------------------------------------------

Example 10: How to Connect iperf Server on UDP Port 

If you want to connect Server on UDP Port instead of default TCP Port then you need to use -u option with iperf command as shown below. In this example, we are trying to connect Server 192.168.0.100 on UDP Port 5001 instead of connecting to default TCP Port.

[root@localhost ~]# iperf -c 192.168.0.100 -u
------------------------------------------------------------
Client connecting to 192.168.0.100, UDP port 5001
Sending 1470 byte datagrams, IPG target: 11215.21 us (kalman adjust)
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.106 port 53674 connected with 192.168.0.100 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 1.25 MBytes 1.05 Mbits/sec
[ 3] Sent 892 datagrams
[ 3] Server Report:
[ 3] 0.0-10.0 sec 1.25 MBytes 1.05 Mbits/sec 0.006 ms 0/ 892 (0%)

-u : use UDP rather than TCP

Now you can go to Server end and verify the response as shown below.

------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 53674
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 3] 0.0-10.0 sec 1281 KBytes 128 KBytes/sec 0.006 ms 0/ 892 (0%)

Example 11: How to Check Packet Loss through UDP Connection

If you want to determine the packet loss through the network then UDP is the best way to check and measure this loss. In this example, we are trying to connect Server 192.168.0.100 on UDP Port 5001 with a target bandwidth of 10 Mbits/sec.

[root@localhost ~]# iperf -c 192.168.0.100 -u -b 10m
------------------------------------------------------------
Client connecting to 192.168.0.100, UDP port 5001
Sending 1470 byte datagrams, IPG target: 1176.00 us (kalman adjust)
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.106 port 58487 connected with 192.168.0.100 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 11.9 MBytes 10.0 Mbits/sec
[ 3] Sent 8503 datagrams
[ 3] Server Report:
[ 3] 0.0-10.0 sec 11.9 MBytes 10.0 Mbits/sec 0.009 ms 0/ 8503 (0%)

-b : set the target bandwidth and optional standard devation per <mean>,[<stdev>]

You can also verify once from Server end as shown below.

------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 58487
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 3] 0.0-10.0 sec 12206 KBytes 1221 KBytes/sec 0.009 ms 0/ 8503 (0%)

Example 12: How to Check UDP Network Statistics in Detail

If you want to check all the UDP Network Statistics like Transfer Bandwidth, Jitter, Packet Loss etc then you need to use below iperf commands. In client end, we will send the data to connect to UDP Port on Server 192.168.0.100 using bandwidth of 10 Mbits/sec.

[root@localhost ~]# iperf -c 192.168.0.100 -u -b 10m
------------------------------------------------------------
Client connecting to 192.168.0.100, UDP port 5001
Sending 1470 byte datagrams, IPG target: 1176.00 us (kalman adjust)
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.106 port 35016 connected with 192.168.0.100 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 11.9 MBytes 10.0 Mbits/sec
[ 3] Sent 8504 datagrams
[ 3] Server Report:
[ 3] 0.0-10.0 sec 11.9 MBytes 10.0 Mbits/sec 0.009 ms 0/ 8504 (0%)

You can also verify the stats from Server end as shown below.

[root@localhost ~]# iperf -s -f K -u -i 2
------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 35016
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 3] 0.0- 2.0 sec 2442 KBytes 1221 KBytes/sec 0.006 ms 0/ 1701 (0%)
[ 3] 2.0- 4.0 sec 2442 KBytes 1221 KBytes/sec 0.004 ms 0/ 1701 (0%)
[ 3] 4.0- 6.0 sec 2442 KBytes 1221 KBytes/sec 0.006 ms 0/ 1701 (0%)
[ 3] 6.0- 8.0 sec 2440 KBytes 1220 KBytes/sec 0.009 ms 0/ 1700 (0%)
[ 3] 8.0-10.0 sec 2442 KBytes 1221 KBytes/sec 0.009 ms 0/ 1701 (0%)
[ 3] 0.0-10.0 sec 12208 KBytes 1221 KBytes/sec 0.009 ms 0/ 8504 (0%)

-i : pause n seconds between periodic bandwidth reports

Example 13: How to Launch Parallel Network Bandwidth Tests

If you want to run parallel network bandwidth tests then you need to use -P option iperf command and specify the number of connections as shown below. In this example we are trying to launch 4 Parallel Network Bandwidth tests by connecting 192.168.0.100 Server on Port 5001.

[root@localhost ~]# iperf -c 192.168.0.100 -P 4
------------------------------------------------------------
Client connecting to 192.168.0.100, TCP port 5001
TCP window size: 4.00 MByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.106 port 54380 connected with 192.168.0.100 port 5001
[ 5] local 192.168.0.106 port 54384 connected with 192.168.0.100 port 5001
[ 4] local 192.168.0.106 port 54382 connected with 192.168.0.100 port 5001
[ 6] local 192.168.0.106 port 54386 connected with 192.168.0.100 port 5001
[ ID] Interval Transfer Bandwidth
[ 6] 0.0-10.0 sec 6.80 GBytes 5.84 Gbits/sec
[ 3] 0.0-10.0 sec 6.69 GBytes 5.73 Gbits/sec
[ 5] 0.0-10.0 sec 6.70 GBytes 5.75 Gbits/sec
[ 4] 0.0-10.0 sec 6.58 GBytes 5.63 Gbits/sec
[SUM] 0.0-10.0 sec 26.8 GBytes 22.9 Gbits/sec

-P : number of parallel client threads to run

Similarly you can go to Server end and check the number of client connections as shown below.

------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[ 6] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 54384
[ 7] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 54386
[ 4] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 54380
[ 5] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 54382
[ ID] Interval Transfer Bandwidth
[ 6] 0.0-10.0 sec 7027328 KBytes 699575 KBytes/sec
[ 7] 0.0-10.1 sec 7131648 KBytes 709131 KBytes/sec
[ 4] 0.0-10.1 sec 7010304 KBytes 695462 KBytes/sec
[ 5] 0.0-10.1 sec 6902400 KBytes 685541 KBytes/sec
[SUM] 0.0-10.1 sec 28071680 KBytes 2784871 KBytes/sec

Example 14: How to Test TCP Connection Using Maximum Segment Size

If you want to test TCP Connection using maximum segment size then you need to use -m option with iperf command as shown below. Usually MSS will have the size range from 0-65535 bytes. Hence by specifying -m option with iperf command will use the maximum segment size of 65535 bytes for TCP testing.

[root@localhost ~]# iperf -c 192.168.0.100 -m
------------------------------------------------------------
Client connecting to 192.168.0.100, TCP port 5001
TCP window size: 4.00 MByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.106 port 54390 connected with 192.168.0.100 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 31.0 GBytes 26.6 Gbits/sec
[ 3] MSS size 65483 bytes (MTU 65523 bytes, unknown interface)

-m : print TCP maximum segment size (MTU – TCP/IP header)

Now you can go to Server end and check the response as shown below.

------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[ 4] local 192.168.0.100 port 5001 connected with 192.168.0.106 port 54390
[ ID] Interval Transfer Bandwidth
[ 4] 0.0-10.0 sec 32477952 KBytes 3244064 KBytes/sec

Example 15: How to check other options of iperf commands in Linux

If you want to check all the other options available with iperf command then you need to use iperf --help command as shown below.

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

Client/Server:
-b, --bandwidth #[kmgKMG | pps] bandwidth to send at in bits/sec or packets per second
-e, --enhancedreports use enhanced reporting giving more tcp/udp and traffic information
-f, --format [kmgKMG] format to report: Kbits, Mbits, KBytes, MBytes
-i, --interval # seconds between periodic bandwidth reports
-l, --len #[kmKM] length of buffer in bytes to read or write (Defaults: TCP=128K, v4 UDP=1470, v6 UDP=1450)
-m, --print_mss print TCP maximum segment size (MTU - TCP/IP header)
-o, --output <filename> output the report or error message to this specified file
-p, --port # server port to listen on/connect to
-u, --udp use UDP rather than TCP
--udp-counters-64bit use 64 bit sequence numbers with UDP
-w, --window #[KM] TCP window size (socket buffer size)
-z, --realtime request realtime scheduler
-B, --bind <host>[:<port>][%<dev>] bind to <host>, ip addr (including multicast address) and optional port and device
-C, --compatibility for use with older versions does not sent extra msgs
-M, --mss # set TCP maximum segment size (MTU - 40 bytes)
-N, --nodelay set TCP no delay, disabling Nagle's Algorithm
-S, --tos # set the socket's IP_TOS (byte) field

 

 

Popular Recommendations:-

How to Cleanup Failed Actions from PCS Status of Cluster

How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8

10 Popular Examples of sudo command in Linux(RedHat/CentOS 7/8)

How to Install and Use telnet command in Linux (RedHat/Linux 7/8) using 5 Easy Steps

12 Most Popular rm command in Linux with Examples

Create a Self Signed Certificate using OpenSSL

Leave a Comment