Test Network Throughput with Iperf Tool on Linux: Best Network Testing with Iperf3

Posted on

Test Network Throughput with Iperf Tool on Linux: Best Network Testing with Iperf3

Test Network Throughput with Iperf Tool on Linux: Best Network Testing with Iperf3

In this guide, you will learn to Test Network Throughput with Iperf Tool on Linux. Iperf is a commonly used network testing tool that can create TCP and UDP data streams and measure the throughput of a network that is carrying them. It’s a crucial tool for network administrators and engineers who need to understand and optimize network performance.

Iperf allows the user to set various parameters that can be used for testing a network, or alternatively for optimizing or tuning a network. It has a client and server functionality and can measure the throughput between the two ends, either unidirectionally or bi-directionally. It is open-source software and runs on various platforms including Linux, Unix, and Windows. The ability to tailor the tests with specific parameters makes it a versatile tool for various network testing scenarios.

Iperf comes with Iperf2 and Iperf3.

Iperf3, first released in 2014, is mainly used to test networks, while Iperf2 is better suited to measuring Wi-Fi speeds. When end users refer to Iperf, they are typically talking about Iperf3, but both versions can run similar tests and provide similar results. This article will focus on using Iperf3 to Test Network Throughput with Iperf Tool on Linux.

Now follow the steps below on the Orcacore website to Test Network Throughput with Iperf Tool on Linux.

To complete this guide for Iperf3 commands, you must log in to your Linux server and follow the steps below.

Step 1. Install Iperf Tool on Linux

The Iperf packages are available in the default Linux repositories. To install it, you can use the following commands.

Install iperf3 on Debian/Ubuntu:

apt-get install iperf3

Install iperf3 on RHEL/CentOS:

# yum install epel-release
# yum install iperf3

And Install iperf3 on RHEL 9/Fedora 22 and later:

dnf install iperf3

At this point, to see your installation is completed, run the command below:

iperf3
**Output**
iperf3: parameter error - must either be a client (-c) or server (-s)

Usage: iperf3 [-s|-c host] [options]
       iperf3 [-h|--help] [-v|--version]

Server or Client:
  -p, --port      #         server port to listen on/connect to
  -f, --format   [kmgtKMGT] format to report: Kbits, Mbits, Gbits, Tbits
  -i, --interval  #         seconds between periodic throughput reports
  -F, --file name           xmit/recv the specified file
  -A, --affinity n/n,m      set CPU affinity
  -B, --bind      <host>    bind to the interface associated with the address <host>
...

Step 2. Test Network Throughput between Server and Client with Iperf3 Commands

At this point, you can check the bandwidth between the two systems. For this, you need two servers one of them is set as the server and the other is set as the client.

Run the TCP Traffic Using Iperf3 Commands

Set Iperf Server: To set your system as an Iperf server, you need to run the following command:

iperf3 -s
Run the TCP Traffic Using Iperf3 Commands

Connect Client to the Iperf server: Now log in to your client machine and run the command below to connect to your Iperf server on Linux:

iperf3 -c <server-ip-address> -i1 -t20

With this option, after the 20sec [-t20] run, the client will be stopped.

After running this command, you will start to get network throughput statistics both on the Iperf client and server on Linux.

**Server Output**
Accepted connection from client-ip, port 51219

[  5] local server-ip port 5201 connected to client-ip port 51220

[ ID] Interval           Transfer     Bandwidth

[  5]   0.00-1.00   sec  1.35 MBytes  11.3 Mbits/sec

[  5]   1.00-2.00   sec  1.53 MBytes  12.8 Mbits/sec

[  5]   2.00-3.00   sec  1.62 MBytes  13.6 Mbits/sec

[  5]   3.00-4.00   sec  1.67 MBytes  14.0 Mbits/sec

[  5]   4.00-5.00   sec  1.67 MBytes  14.0 Mbits/sec

[  5]   5.00-6.00   sec  1.46 MBytes  12.3 Mbits/sec

[  5]   6.00-7.00   sec  1.45 MBytes  12.2 Mbits/sec

[  5]   7.00-8.00   sec  1.59 MBytes  13.3 Mbits/sec

[  5]   8.00-9.00   sec  1.78 MBytes  14.9 Mbits/sec

[  5]   9.00-10.00  sec  1.32 MBytes  11.1 Mbits/sec

[  5]  10.00-11.00  sec  1.19 MBytes  9.95 Mbits/sec

[  5]  11.00-12.00  sec  1.12 MBytes  9.37 Mbits/sec

[  5]  12.00-13.00  sec  1.41 MBytes  11.9 Mbits/sec

[  5]  13.00-14.00  sec  1.60 MBytes  13.4 Mbits/sec

[  5]  14.00-15.00  sec  1.50 MBytes  12.6 Mbits/sec

[  5]  15.00-16.00  sec  1.71 MBytes  14.4 Mbits/sec

[  5]  16.00-17.00  sec  1.48 MBytes  12.4 Mbits/sec

[  5]  17.00-18.00  sec  1.47 MBytes  12.3 Mbits/sec

[  5]  18.00-19.00  sec  1.37 MBytes  11.5 Mbits/sec

[  5]  19.00-20.00  sec  1.50 MBytes  12.5 Mbits/sec

[  5]  20.00-20.11  sec   236 KBytes  17.6 Mbits/sec

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bandwidth

[  5]   0.00-20.11  sec  30.0 MBytes  12.5 Mbits/sec                  sender

[  5]   0.00-20.11  sec  30.0 MBytes  12.5 Mbits/sec                  receiver

-----------------------------------------------------------

Server listening on 5201

-----------------------------------------------------------
**Client Output**
Connecting to host server-ip, port 5201

[  4] local client-ip port 51220 connected to server-ip port 5201

[ ID] Interval           Transfer     Bandwidth

[  4]   0.00-1.01   sec  1.56 MBytes  13.0 Mbits/sec

[  4]   1.01-2.02   sec  1.56 MBytes  13.0 Mbits/sec

[  4]   2.02-3.00   sec  1.56 MBytes  13.4 Mbits/sec

[  4]   3.00-4.01   sec  1.69 MBytes  14.0 Mbits/sec

[  4]   4.01-5.01   sec  1.69 MBytes  14.2 Mbits/sec

[  4]   5.01-6.00   sec  1.44 MBytes  12.2 Mbits/sec

[  4]   6.00-7.00   sec  1.37 MBytes  11.5 Mbits/sec

[  4]   7.00-8.01   sec  1.75 MBytes  14.5 Mbits/sec

[  4]   8.01-9.00   sec  1.62 MBytes  13.7 Mbits/sec

[  4]   9.00-10.00  sec  1.37 MBytes  11.6 Mbits/sec

[  4]  10.00-11.01  sec  1.12 MBytes  9.34 Mbits/sec

[  4]  11.01-12.00  sec  1.19 MBytes  10.1 Mbits/sec

[  4]  12.00-13.02  sec  1.44 MBytes  11.8 Mbits/sec

[  4]  13.02-14.01  sec  1.56 MBytes  13.2 Mbits/sec

[  4]  14.01-15.00  sec  1.50 MBytes  12.7 Mbits/sec

[  4]  15.00-16.01  sec  1.81 MBytes  15.1 Mbits/sec

[  4]  16.01-17.01  sec  1.37 MBytes  11.5 Mbits/sec

[  4]  17.01-18.00  sec  1.44 MBytes  12.2 Mbits/sec

[  4]  18.00-19.00  sec  1.31 MBytes  11.0 Mbits/sec

[  4]  19.00-20.00  sec  1.62 MBytes  13.6 Mbits/sec

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bandwidth

[  4]   0.00-20.00  sec  30.0 MBytes  12.6 Mbits/sec                  sender

[  4]   0.00-20.00  sec  30.0 MBytes  12.6 Mbits/sec                  receiver

iperf Done.

Run the UDP Traffic Using Iperf3 Commands

To set the Iperf server, the same as the TCP, run the command below:

iperf3 -s

For the UDP client, you should run the command below:

iperf3 -c <server-ip> -i1 -t5 -u -b100M
**Server Output**
Accepted connection from client-ip, port 51321

[  5] local server-ip port 5201 connected to client-ip port 54181

[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams

[  5]   0.00-1.00   sec  1.30 MBytes  10.9 Mbits/sec  313523.501 ms  0/167 (0%)

[  5]   1.00-2.00   sec  1.34 MBytes  11.3 Mbits/sec  16.624 ms  5/177 (2.8%)

[  5]   2.00-3.00   sec  1.99 MBytes  16.7 Mbits/sec  10.843 ms  0/255 (0%)

[  5]   3.00-4.00   sec   672 KBytes  5.50 Mbits/sec  3.955 ms  0/84 (0%)

[  5]   4.00-5.00   sec  1.98 MBytes  16.6 Mbits/sec  14.042 ms  8/261 (3.1%)

[  5]   5.00-5.68   sec   960 KBytes  11.6 Mbits/sec  3.389 ms  0/120 (0%)

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams

[  5]   0.00-5.68   sec  8.31 MBytes  12.3 Mbits/sec  3.389 ms  13/1064 (1.2%)
**Client Output**
Connecting to host server-ip, port 5201

[  4] local client-ip port 54181 connected to server-ip port 5201

[ ID] Interval           Transfer     Bandwidth       Total Datagrams

[  4]   0.00-1.23   sec  1.38 MBytes  9.40 Mbits/sec  176

[  4]   1.23-2.00   sec  1.73 MBytes  18.7 Mbits/sec  221

[  4]   2.00-3.12   sec  1.65 MBytes  12.3 Mbits/sec  211

[  4]   3.12-4.01   sec  1.76 MBytes  16.6 Mbits/sec  225

[  4]   4.01-5.03   sec  1.80 MBytes  14.8 Mbits/sec  231

- - - - - - - - - - - - - - - - - - - - - - - - -

[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams

[  4]   0.00-5.03   sec  8.31 MBytes  13.9 Mbits/sec  3.389 ms  13/1064 (1.2%)

[  4] Sent 1064 datagrams

To get more help and other options for Iperf3 Commands, you can use the command below:

iperf3 --help

Also, you can visit the Iperf Docs page.

Conclusion

iPerf3 is a powerful tool used by network administrators, engineers, and testers to measure and analyze the performance of a network, helping identify bottlenecks and optimize network setups. This article provided a guide on how to Test Network Throughput with Iperf Tool on Linux.

Hope you enjoy Iperf3 Commands. Also, you may like these articles:

How To Enable IP Forwarding in Linux

How To Install mtr Command on Linux

Use nslookup Command in Linux

Alternative Solutions for Network Throughput Testing

While Iperf3 is a robust and widely used tool, alternative methods exist for testing network throughput, each with its own advantages and disadvantages. Here are two such alternatives:

1. Using netcat (nc)

netcat (or nc) is a versatile networking utility often described as a "Swiss army knife" for networking. It can be used for various tasks, including creating network connections, listening on arbitrary TCP and UDP ports, and transferring data. While not specifically designed for network throughput testing like Iperf3, it can be adapted for this purpose.

Explanation:

The basic principle is to use netcat to send a large amount of data from one host (the client) to another (the server) and then measure the time it takes for the transfer to complete. By knowing the size of the data transferred and the time taken, we can calculate the throughput. This method provides a simple and quick way to estimate network performance.

Example:

Server (listening):

nc -l -p 5001 > /dev/null

This command tells netcat to listen on port 5001 and discard all received data to /dev/null.

Client (sending):

dd if=/dev/zero bs=1M count=100 | nc <server-ip> 5001

This command uses dd to generate 100MB of data (1MB blocks of zeros) and pipes it to netcat, which then sends the data to the server at <server-ip> on port 5001. To calculate the throughput, measure the time this command takes to complete.

Calculating Throughput:

If the above command takes 10 seconds to complete, the throughput is approximately 100MB / 10 seconds = 10MB/s or 80 Mbps.

Advantages:

  • Simple to use and readily available on most Linux systems.
  • Doesn’t require installing additional software (like Iperf3).

Disadvantages:

  • Less precise than Iperf3, as it doesn’t account for network overhead or provide detailed statistics like jitter or packet loss.
  • Requires manual calculation of throughput.
  • Not as configurable as Iperf3 for specific testing scenarios.

2. Using wget or curl for HTTP Throughput Testing

If you want to specifically test the throughput of HTTP connections, you can use wget or curl to download a large file from an HTTP server and measure the download time. This is particularly useful for testing web server performance or the network connection to a specific web server.

Explanation:

This method leverages the existing infrastructure of HTTP servers and clients. By downloading a known-size file, you can easily calculate the effective throughput of the HTTP connection.

Example (using wget):

wget --output-document=/dev/null http://<server-ip>/largefile.dat

Replace <server-ip> with the IP address or hostname of the HTTP server and largefile.dat with the path to a large file (e.g., 100MB or larger). The --output-document=/dev/null option discards the downloaded file, preventing it from being saved to disk.

Example (using curl):

curl -o /dev/null http://<server-ip>/largefile.dat

Similarly, this command downloads the file and discards it.

Calculating Throughput:

wget and curl usually display the download speed in their output after the download is complete. If they don’t, you can time the command execution and calculate the throughput manually: Throughput = File Size / Download Time.

Advantages:

  • Tests HTTP-specific throughput, which is relevant for web applications.
  • Leverages existing HTTP infrastructure.
  • Easy to implement with common command-line tools.

Disadvantages:

  • Only tests HTTP throughput, not general network throughput.
  • Results can be influenced by the performance of the HTTP server.
  • Less granular control over test parameters compared to Iperf3.

In conclusion, while Iperf3 remains the preferred tool for comprehensive network throughput testing, netcat and wget/curl offer simpler alternatives for quick estimations or specific HTTP testing scenarios. Choosing the right tool depends on the specific testing requirements and the level of detail needed. These alternative approaches can be used to Test Network Throughput with Iperf Tool on Linux, but not as effectively.

Leave a Reply

Your email address will not be published. Required fields are marked *