iperf ‐ #networking - five4nets/Linux-Knowledgebase GitHub Wiki

Tutorial: Using the Linux iperf Command

iperf is a powerful command-line tool for measuring network performance, including bandwidth, latency, and packet loss. It operates in a client-server model, allowing you to test network throughput between two systems. This tutorial covers iperf installation, basic usage, command explanations, and practical examples.

Prerequisites

  • Two Linux systems (one as server, one as client).
  • Network connectivity between the systems.
  • Root or sudo privileges for installation.

Installation

Install iperf on both systems. For Debian-based distributions (e.g., Ubuntu):

sudo apt update
sudo apt install iperf

For Red Hat-based distributions (e.g., CentOS, Fedora):

sudo yum install iperf

For iperf3 (a newer version):

sudo apt install iperf3  # Debian-based
sudo yum install iperf3  # Red Hat-based

Verify installation:

iperf --version
iperf3 --version

Basic Usage

iperf requires one system to act as the server and another as the client.

Starting the Server

On the server system, run:

iperf -s

For iperf3:

iperf3 -s
  • -s: Specifies server mode.
  • The server listens on the default port 5001 (iperf) or 5201 (iperf3).

Running the Client

On the client system, connect to the server (replace server_ip with the server's IP address):

iperf -c server_ip

For iperf3:

iperf3 -c server_ip
  • -c: Specifies client mode and the server to connect to.
  • This runs a 10-second test by default, measuring throughput.

Common Options

Here are key iperf/iperf3 options:

Option Description Example
-p Specify port iperf -s -p 5100
-t Test duration (seconds) iperf -c server_ip -t 20
-i Interval for reporting (seconds) iperf -c server_ip -i 2
-u Use UDP instead of TCP iperf -c server_ip -u
-b Bandwidth limit (UDP only) iperf -c server_ip -u -b 10M
-P Number of parallel streams iperf -c server_ip -P 4
-f Format output (k, m, g for Kbps, Mbps, Gbps) iperf -c server_ip -f m
-R Reverse test (server sends, client receives) iperf3 -c server_ip -R

Examples

Example 1: Basic TCP Test

Measure TCP bandwidth between client and server.

  • Server:
    iperf -s
    
  • Client:
    iperf -c 192.168.1.100 -t 15 -i 3
    
  • Explanation:
    • Runs a 15-second test (-t 15).
    • Reports every 3 seconds (-i 3).
    • Output shows bandwidth (e.g., [ ID: 123] Interval: 0-15s Transfer: 1.2Gbps).

Example 2: UDP Test with Bandwidth Limit

Test UDP performance with a 5 Mbps limit.

  • Server:
    iperf3 -s -p 6000
    
  • Client:
    iperf3 -c 192.168.1.100 -p 6000 -u -b 5M -t 10
    
  • Explanation:
    • Uses UDP (-u) on port 6000 (-p 6000).
    • Limits bandwidth to 5 Mbps (-b 5M).
    • Runs for 10 seconds.
    • Output includes jitter and packet loss (e.g., Lost/Total: 0.2%).

Example 3: Parallel Streams

Test with multiple TCP streams to maximize bandwidth.

  • Server:
    iperf -s
    
  • Client:
    iperf -c 192.168.1.100 -P 8 -f m
    
  • Explanation:
    • Uses 8 parallel streams (-P 8).
    • Reports in Mbps (-f m).
    • Useful for high-bandwidth networks.

Example 4: Bidirectional Test

Test bandwidth in both directions simultaneously (iperf3 only).

  • Server:
    iperf3 -s
    
  • Client:
    iperf3 -c 192.168.1.100 --bd=2
    
  • Explanation:
    • --bd=2 runs two parallel streams
    • Output shows both upload and download speeds.

Example 5: Reverse Test

Test server-to-client (iperf3 only).

  • Server:
    iperf3 -s
    
  • Client:
    iperf3 -c 192.168.1.100 -R
    
  • Explanation:
    • -R: Reverses the test direction
    • Useful for testing asymmetric links.

Interpreting Output

  • TCP: Look for Bandwidth (e.g., 1.5 Gbps) in the summary.
  • UDP: Check Jitter (e.g., 0.5ms) and Lost/Total for packet loss.
  • Parallel Streams: Sum the bandwidth of each stream to get total throughput.
  • Example TCP output:
    [ ID: 123] Interval: 0-10s Transfer: 1125MB Bandwidth: 900Mbps
    
  • Example UDP output:
    [ ID: 123] Interval: 0-10s Transfer: 50MB Bandwidth: 40Mbps Jitter: 0.3ms Lost/Total: 5/10000 (0.05%)
    

Troubleshooting

  • Connection refused: Ensure the server allows incoming traffic on the specified port (e.g., ufw allow 5201 or update iptablesiptables).
  • Low performance: Check network congestion, CPU usage, or try multiple streams (-P).
  • iperf vs. iperf3: Some options differ; use the same version on both systems for compatibility.

References