In the world of Linux system administration and networking, accurately measuring network performance is crucial for troubleshooting bottlenecks, verifying new hardware, or simply understanding your network’s capacity. While tools like ping
can tell you about latency and reachability, they don’t provide a complete picture of throughput. This is where iperf comes in.
This article will break down what iperf is, how it works, and how you can use it to test network performance with practical examples.
What is iperf?
iperf is a powerful command-line tool used for network performance measurement and tuning. It is designed to measure the maximum achievable bandwidth on an IP network, supporting both TCP and UDP protocols. By generating traffic and reporting on its performance, iperf helps you determine the speed and reliability of a network link between two points.
The core concept behind iperf is its client-server architecture. To run a test, you must have one machine configured as the server (the receiving end) and another as the client (the sending end).
- Server: Listens for incoming connections on a specified port.
- Client: Connects to the server and generates a stream of data to measure throughput.
How iperf Works
The process is straightforward:
- Start the Server: You begin by launching the
iperf
command on the destination machine in server mode. This machine will wait for a connection from the client. - Start the Client: On the source machine, you run
iperf
in client mode, specifying the IP address or hostname of the server. - Data Transfer: The client then sends data to the server. For TCP tests, iperf measures the data that is successfully transferred, providing an accurate measure of maximum throughput. For UDP tests, iperf sends a constant stream of data at a specified bitrate and reports on metrics like jitter, datagram loss, and throughput.
iperf Command Examples
Before you begin, ensure iperf is installed on both machines. On most Debian/Ubuntu systems, you can install it using: sudo apt install iperf
1. Basic TCP Test
This is the most common use case. It measures the maximum TCP bandwidth between two hosts.
- On the Server:
iperf -s
The -s
flag tells iperf to run in server mode. The server will start listening for connections on the default port (5001).
- On the Client:
iperf -c 192.168.1.10
The -c
flag indicates client mode, and 192.168.1.10
is the IP address of the server. The client will connect, run a 10-second test by default, and then display a report.
Example output:
------------------------------------------------------------
Client connecting to 192.168.1.10, TCP port 5001
TCP window size: 1.00 MByte (default)
------------------------------------------------------------
[ 3] local 192.168.1.5 port 45123 connected with 192.168.1.10 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 1.00 GBytes 858 Mbits/sec
The key metric here is the Bandwidth, which shows the average throughput over the test duration.
2. Customizing Your Test
iperf offers several options to fine-tune your measurements.
- Change the port: Use the
-p
flag on both the client and server.
# Server
iperf -s -p 5200
# Client
iperf -c 192.168.1.10 -p 5200
- Change the duration: Use the
-t
flag on the client to specify the test duration in seconds.
# Run a 60-second test
iperf -c 192.168.1.10 -t 60
- Increase parallel streams: The
-P
flag on the client can simulate multiple connections, which is useful for testing high-bandwidth links and multi-core performance.
# Use 4 parallel streams
iperf -c 192.168.1.10 -P 4
3. UDP Test
Unlike TCP, UDP is a connectionless protocol that does not guarantee delivery. iperf’s UDP test measures the data transfer rate, packet loss, and jitter.
- On the Server:
iperf -s -u
The -u
flag specifies UDP mode.
- On the Client:
iperf -c 192.168.1.10 -u -b 100M
The -u
flag is essential, and the -b
flag sets the target bandwidth for the UDP stream (e.g., 100 Mbps).
Example output:
------------------------------------------------------------
Client connecting to 192.168.1.10, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size: 2.00 MByte (default)
------------------------------------------------------------
[ 3] local 192.168.1.5 port 55678 connected with 192.168.1.10 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 125 MBytes 105 Mbits/sec
[ 3] Sent 89280 datagrams
[ 3] Server Report:
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 3] 0.0-10.0 sec 105 MBytes 88.5 Mbits/sec 0.038 ms 1/89280 (0.0011%)
The server report for UDP is more detailed, showing Jitter (variation in delay) and Lost/Total Datagrams (packet loss).
Why iperf is a Must-Have Tool
iperf is an indispensable tool for network diagnostics. Whether you’re a professional network engineer or a home user trying to figure out why your file transfers are slow, iperf provides a clear, quantitative measure of your network’s true performance, allowing you to move beyond guesswork and pinpoint actual network issues.