1. Overview

In this tutorial, we’ll learn how to use the iPerf tool to measure network performance and bandwidth.

iPerf is an open-source tool written in the C programming language. Moreover, it works in a client-server model and supports UDP and TCP. Therefore, we need to have two systems that both have the tool installed. First, we need to initiate the server. After that, we need to connect to the server from the client machine.

2. Installing iPerf on Client and Server

We need to install iPerf on both the client and the server:

$ sudo apt install iperf

After that, we should check if it’s installed:

$ iperf --version
iperf version 2.0.13 (21 Jan 2019) pthreads

The procedure is the same on both machines assuming they are both running Ubuntu/Debian.

3. Initiating the Server

After installing iPerf, we need to initiate the server:

# iperf -s 
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------

The server is now listening on TCP port 5001. By default, iPerf uses TCP and will listen on port 5001.

Optional flags that we can include:

  • -u will make the server use UDP rather than TCP
  • -p will change the default port

For example, let’s make the server use UDP and listen on port 5003:

# iperf -s -u -p 5003
------------------------------------------------------------
Server listening on UDP port 5003
Receiving 1470 byte datagrams
UDP buffer size:  208 KByte (default)
------------------------------------------------------------

The server is now listening on UDP port 5003.

4. Connecting to the Server From the Client

We can use TCP or UDP.

4.1. Using TCP

After initiating the server, we should connect to it from the client machine:

$ iperf -c 5.182.18.49
------------------------------------------------------------
Client connecting to 5.182.18.49, TCP port 5001
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[  3] local 192.168.1.24 port 38616 connected with 5.182.18.49 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.1 sec  6.12 MBytes  5.10 Mbits/sec

iperf -c 5.182.18.49 will start a connection to the server with IP address 5.182.18.49.

We can see that the default TCP window size of 85 KB has been used. Also, the interval time is 10 seconds. In addition, 6.12 MB has been transferred. Finally, the bandwidth is 5.10 Mbits/sec, which shows the performance.

Optional flags that we can include:

  • -i specifies the interval time in seconds. 10 is the default
  • -t specifies the time to run the test in seconds
  • -p specifies the port. 5001 is the default
  • -w specifies the TCP window size. 85 KB is the default

Let’s use some of the optional flags:

 iperf -c 5.182.18.49 -i 5 -t 15 -w 416K -p 5003
------------------------------------------------------------
Client connecting to 5.182.18.49, TCP port 5003
TCP window size:  416 KByte
------------------------------------------------------------
[  3] local 192.168.1.24 port 47300 connected with 5.182.18.49 port 5003
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 5.0 sec  2.88 MBytes  4.82 Mbits/sec
[  3]  5.0-10.0 sec  2.75 MBytes  4.61 Mbits/sec
[  3] 10.0-15.0 sec  2.75 MBytes  4.61 Mbits/sec
[  3]  0.0-15.2 sec  8.38 MBytes  4.62 Mbits/sec

We set the interval time to 5 seconds. In addition, we set the test duration to 15 seconds and the TCP window size to 416 KB. Finally, we set the port to 5003. Most importantly, the server needs to be listening on port 5003 instead of 5001 for the connection to be established.

4.2. Using UDP

Alternatively, we can use UDP instead of TCP. Certainly, the server needs to be using UDP as well.

$ iperf -c 5.182.18.49 -u
------------------------------------------------------------
Client connecting to 5.182.18.49, UDP port 5001
Sending 1470 byte datagrams, IPG target: 11215.21 us (kalman adjust)
UDP buffer size:  208 KByte (default)
------------------------------------------------------------
[  3] local 192.168.1.24 port 45640 connected with 5.182.18.49 port 5001
[  3] WARNING: did not receive ack of last datagram after 10 tries.
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  1.25 MBytes  1.05 Mbits/sec
[  3] Sent 892 datagrams

We notice that the bandwidth is much lower than TCP. The reason is that iPerf limits the bandwidth for UDP to 1Mbits/sec by default. However, we can replace the limit by adding the -b flag:

$ iperf -c 5.182.18.49 -u -b 1000M
------------------------------------------------------------
Client connecting to 5.182.18.49, UDP port 5001
Sending 1470 byte datagrams, IPG target: 11.22 us (kalman adjust)
UDP buffer size:  208 KByte (default)
------------------------------------------------------------
[  3] local 192.168.1.24 port 56981 connected with 5.182.18.49 port 5001
[  3] WARNING: did not receive ack of last datagram after 10 tries.
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   180 MBytes   151 Mbits/sec
[  3] Sent 128140 datagrams

We can see that the bandwidth is significantly higher now.

5. Conclusion

In this article, we learned how to initiate a server and run iPerf on the client machine to measure network performance and bandwidth.