Testing Linux Network Performance with iperf3
Table of Contents
- [Introduction](#introduction) - [Installation](#installation) - [Basic Concepts](#basic-concepts) - [Command Syntax and Options](#command-syntax-and-options) - [Server Configuration](#server-configuration) - [Client Configuration](#client-configuration) - [Testing Scenarios](#testing-scenarios) - [Advanced Features](#advanced-features) - [Performance Optimization](#performance-optimization) - [Troubleshooting](#troubleshooting) - [Real-World Examples](#real-world-examples)Introduction
iperf3 is a powerful network testing tool designed to measure the maximum achievable bandwidth on IP networks. It supports tuning of various parameters related to timing, protocols, and buffers. For each test, it reports the measured throughput, loss, and other parameters. This tool is essential for network administrators, system engineers, and anyone who needs to validate network performance, diagnose connectivity issues, or benchmark network infrastructure.
Unlike its predecessor iperf2, iperf3 has been completely rewritten from scratch and offers improved accuracy, better reporting, and enhanced features. It operates on a client-server model where one system acts as a server listening for connections, and another acts as a client initiating the test.
Installation
Ubuntu/Debian Systems
`bash
Update package repository
sudo apt updateInstall iperf3
sudo apt install iperf3Verify installation
iperf3 --version`CentOS/RHEL/Fedora Systems
`bash
For CentOS/RHEL 7/8
sudo yum install iperf3For Fedora and newer RHEL versions
sudo dnf install iperf3Verify installation
iperf3 --version`Compilation from Source
`bash
Install development tools
sudo apt install build-essentialDownload source code
wget https://github.com/esnet/iperf/archive/3.12.tar.gz tar -xzf 3.12.tar.gz cd iperf-3.12Configure, compile, and install
./configure make sudo make install`Basic Concepts
Client-Server Architecture
iperf3 operates using a client-server model:
- Server: Listens for incoming connections on a specified port (default 5201) - Client: Initiates connections to the server and performs the actual test - Bidirectional Testing: Both systems can act as client and server simultaneously
Test Types
| Test Type | Description | Use Case | |-----------|-------------|----------| | TCP | Reliable, connection-oriented protocol | Measuring maximum throughput | | UDP | Unreliable, connectionless protocol | Testing packet loss and jitter | | SCTP | Stream Control Transmission Protocol | Multi-homing and multi-streaming |
Measurement Metrics
| Metric | Description | Units | |--------|-------------|-------| | Bandwidth | Data transfer rate | Mbits/sec, Gbits/sec | | Throughput | Actual data transmission rate | Mbits/sec, Gbits/sec | | Jitter | Variation in packet delay | milliseconds | | Packet Loss | Percentage of lost packets | percentage | | Retransmissions | TCP segments retransmitted | count |
Command Syntax and Options
Basic Syntax
`bash
Server mode
iperf3 -s [options]Client mode
iperf3 -c`Essential Options
| Option | Long Form | Description | Example |
|--------|-----------|-------------|---------|
| -s | --server | Run in server mode | iperf3 -s |
| -c | --client | Run in client mode | iperf3 -c 192.168.1.100 |
| -p | --port | Server port number | iperf3 -s -p 5202 |
| -t | --time | Test duration in seconds | iperf3 -c server -t 30 |
| -i | --interval | Reporting interval | iperf3 -c server -i 2 |
| -P | --parallel | Number of parallel streams | iperf3 -c server -P 4 |
| -u | --udp | Use UDP protocol | iperf3 -c server -u |
| -b | --bandwidth | Target bandwidth | iperf3 -c server -u -b 100M |
| -R | --reverse | Reverse test direction | iperf3 -c server -R |
| -w | --window | TCP window size | iperf3 -c server -w 64K |
| -M | --set-mss | TCP MSS size | iperf3 -c server -M 1460 |
Advanced Options
| Option | Long Form | Description | Example |
|--------|-----------|-------------|---------|
| -J | --json | Output in JSON format | iperf3 -c server -J |
| -O | --omit | Omit initial seconds | iperf3 -c server -O 5 |
| -T | --title | Test title prefix | iperf3 -c server -T "LAN Test" |
| -C | --congestion | TCP congestion control | iperf3 -c server -C cubic |
| -Z | --zerocopy | Use zero-copy method | iperf3 -c server -Z |
| -A | --affinity | CPU affinity | iperf3 -c server -A 2 |
| -B | --bind | Bind to interface | iperf3 -c server -B eth1 |
| -4 | --version4 | Force IPv4 | iperf3 -c server -4 |
| -6 | --version6 | Force IPv6 | iperf3 -c server -6 |
Server Configuration
Basic Server Setup
`bash
Start server on default port 5201
iperf3 -sStart server on custom port
iperf3 -s -p 8080Start server with verbose output
iperf3 -s -VStart server as daemon
iperf3 -s -D`Server with Specific Interface
`bash
Bind server to specific IP address
iperf3 -s -B 192.168.1.100Bind server to specific interface
iperf3 -s -B eth0IPv6 server
iperf3 -s -6 -B 2001:db8::1`Server Configuration File
Create a systemd service for persistent iperf3 server:
`bash
Create service file
sudo nano /etc/systemd/system/iperf3.service``ini
[Unit]
Description=iperf3 server
After=network.target
[Service] Type=simple User=iperf3 ExecStart=/usr/bin/iperf3 -s -p 5201 Restart=always RestartSec=10
[Install]
WantedBy=multi-user.target
`
`bash
Create user for service
sudo useradd -r -s /bin/false iperf3Enable and start service
sudo systemctl enable iperf3 sudo systemctl start iperf3 sudo systemctl status iperf3`Client Configuration
Basic Client Tests
`bash
Simple throughput test
iperf3 -c 192.168.1.100Test for 60 seconds with 5-second intervals
iperf3 -c 192.168.1.100 -t 60 -i 5Test with 4 parallel streams
iperf3 -c 192.168.1.100 -P 4Reverse test (server sends to client)
iperf3 -c 192.168.1.100 -R`UDP Performance Testing
`bash
Basic UDP test with 100 Mbps target
iperf3 -c 192.168.1.100 -u -b 100MUDP test with custom packet size
iperf3 -c 192.168.1.100 -u -b 1G -l 1024UDP test measuring jitter
iperf3 -c 192.168.1.100 -u -b 100M -t 30 -i 1`Bidirectional Testing
`bash
Simultaneous bidirectional test
iperf3 -c 192.168.1.100 --bidirSequential bidirectional test
iperf3 -c 192.168.1.100 -t 30 iperf3 -c 192.168.1.100 -R -t 30`Testing Scenarios
Scenario 1: LAN Performance Testing
Objective: Test maximum throughput between two systems on the same network segment.
Server Setup:
`bash
Start server with verbose logging
iperf3 -s -V -i 1`Client Commands:
`bash
Basic throughput test
iperf3 -c 192.168.1.100 -t 30 -i 5Multi-stream test
iperf3 -c 192.168.1.100 -P 8 -t 30Large window size for high-speed networks
iperf3 -c 192.168.1.100 -w 256K -t 30`Expected Results: - Gigabit Ethernet: ~940 Mbps - 10 Gigabit Ethernet: ~9.4 Gbps - Fast Ethernet: ~94 Mbps
Scenario 2: WAN Performance Testing
Objective: Measure performance across wide area networks with higher latency.
Server Setup:
`bash
Server with extended timeout
iperf3 -s --idle-timeout 120`Client Commands:
`bash
Long duration test with larger window
iperf3 -c wan.server.com -t 300 -w 1M -i 10Test with congestion control optimization
iperf3 -c wan.server.com -C bbr -t 180Multiple parallel streams for WAN
iperf3 -c wan.server.com -P 4 -t 120`Scenario 3: Wireless Network Testing
Objective: Evaluate wireless network performance and identify interference.
Client Commands:
`bash
Basic wireless test
iperf3 -c 192.168.1.1 -t 60 -i 2UDP test to measure packet loss
iperf3 -c 192.168.1.1 -u -b 50M -t 60Bidirectional test for wireless
iperf3 -c 192.168.1.1 --bidir -t 30`Scenario 4: Network Troubleshooting
Objective: Diagnose network issues and bottlenecks.
Diagnostic Commands:
`bash
Test with small packets
iperf3 -c server -l 64 -t 30Test with jumbo frames
iperf3 -c server -M 9000 -t 30CPU affinity testing
iperf3 -c server -A 1 -t 30 iperf3 -c server -A 2 -t 30`Advanced Features
JSON Output and Parsing
`bash
Generate JSON output
iperf3 -c 192.168.1.100 -J -t 10 > test_results.jsonParse JSON with jq
iperf3 -c 192.168.1.100 -J | jq '.end.sum_received.bits_per_second'Extract specific metrics
iperf3 -c server -J | jq '.end.sum_sent.bytes, .end.sum_sent.seconds'`Custom Congestion Control
`bash
List available congestion control algorithms
cat /proc/sys/net/ipv4/tcp_available_congestion_controlTest with different algorithms
iperf3 -c server -C cubic -t 30 -T "CUBIC Test" iperf3 -c server -C bbr -t 30 -T "BBR Test" iperf3 -c server -C reno -t 30 -T "RENO Test"`Performance Comparison Table
| Algorithm | Throughput (Mbps) | Retransmissions | RTT (ms) | |-----------|-------------------|-----------------|----------| | CUBIC | 945 | 12 | 1.2 | | BBR | 952 | 8 | 1.1 | | RENO | 923 | 18 | 1.3 |
Zero-Copy and CPU Optimization
`bash
Enable zero-copy for reduced CPU usage
iperf3 -c server -Z -t 30Set CPU affinity
iperf3 -c server -A 2,3 -t 30Combine optimizations
iperf3 -c server -Z -A 2 -w 512K -t 30`Performance Optimization
TCP Window Scaling
The TCP window size significantly impacts performance, especially on high-bandwidth, high-latency networks.
Bandwidth-Delay Product Calculation:
`
Optimal Window Size = Bandwidth × Round Trip Time
`
Examples:
`bash
For 1 Gbps link with 10ms RTT
Window Size = 1,000,000,000 bps × 0.01s = 10,000,000 bits = 1.25 MB
iperf3 -c server -w 1.25MFor 100 Mbps link with 50ms RTT
Window Size = 100,000,000 bps × 0.05s = 5,000,000 bits = 625 KB
iperf3 -c server -w 625K`System Tuning for High Performance
Network Buffer Tuning:
`bash
Increase network buffer sizes
echo 'net.core.rmem_max = 134217728' >> /etc/sysctl.conf echo 'net.core.wmem_max = 134217728' >> /etc/sysctl.conf echo 'net.ipv4.tcp_rmem = 4096 87380 134217728' >> /etc/sysctl.conf echo 'net.ipv4.tcp_wmem = 4096 65536 134217728' >> /etc/sysctl.confApply changes
sudo sysctl -p`CPU and Interrupt Optimization:
`bash
Check interrupt distribution
cat /proc/interrupts | grep eth0Set network interface interrupt affinity
echo 2 > /proc/irq/24/smp_affinityUse specific CPU cores for iperf3
taskset -c 2,3 iperf3 -c server -t 30`Performance Comparison Matrix
| Configuration | Single Stream | 4 Streams | 8 Streams | CPU Usage | |---------------|---------------|-----------|-----------|-----------| | Default | 940 Mbps | 940 Mbps | 940 Mbps | 15% | | Large Window | 945 Mbps | 950 Mbps | 952 Mbps | 18% | | Zero-Copy | 948 Mbps | 955 Mbps | 958 Mbps | 12% | | CPU Affinity | 950 Mbps | 960 Mbps | 965 Mbps | 14% | | Combined | 955 Mbps | 970 Mbps | 975 Mbps | 10% |
Troubleshooting
Common Issues and Solutions
Issue 1: Connection Refused
`bash
Check if server is running
netstat -tlnp | grep 5201Check firewall rules
sudo ufw status sudo iptables -LSolution: Start server and open firewall
iperf3 -s -D sudo ufw allow 5201`Issue 2: Poor Performance
`bash
Check network interface statistics
ip -s link show eth0Check for errors
ethtool -S eth0 | grep errorMonitor CPU usage during test
top -p $(pgrep iperf3)`Issue 3: UDP Packet Loss
`bash
Check receive buffer size
cat /proc/sys/net/core/rmem_default cat /proc/sys/net/core/rmem_maxIncrease buffer size
sudo sysctl -w net.core.rmem_max=26214400 sudo sysctl -w net.core.rmem_default=26214400`Debug Mode and Verbose Output
`bash
Enable debug mode
iperf3 -c server -d -VServer with detailed logging
iperf3 -s -V --logfile /var/log/iperf3.logClient with enhanced output
iperf3 -c server -V -i 1 -t 30`Network Path Analysis
`bash
Trace route to destination
traceroute server.example.comCheck MTU path discovery
ping -M do -s 1472 server.example.comTest with different MSS values
iperf3 -c server -M 1460 -t 10 iperf3 -c server -M 1200 -t 10`Real-World Examples
Example 1: Data Center Network Validation
Scenario: Validating 10 Gigabit Ethernet links between servers in a data center.
Server Configuration:
`bash
Start multiple servers for parallel testing
iperf3 -s -p 5201 -D --logfile /var/log/iperf3-5201.log iperf3 -s -p 5202 -D --logfile /var/log/iperf3-5202.log iperf3 -s -p 5203 -D --logfile /var/log/iperf3-5203.log`Client Test Script:
`bash
#!/bin/bash
SERVER="10.0.1.100"
DURATION=60
RESULTS_DIR="/tmp/network_tests"
mkdir -p $RESULTS_DIR
echo "Starting network performance validation..."
Test 1: Single stream maximum throughput
echo "Test 1: Single stream test" iperf3 -c $SERVER -t $DURATION -J > $RESULTS_DIR/single_stream.jsonTest 2: Multiple parallel streams
echo "Test 2: Multiple streams test" iperf3 -c $SERVER -P 8 -t $DURATION -J > $RESULTS_DIR/multi_stream.jsonTest 3: Bidirectional test
echo "Test 3: Bidirectional test" iperf3 -c $SERVER --bidir -t $DURATION -J > $RESULTS_DIR/bidirectional.jsonTest 4: UDP performance
echo "Test 4: UDP test" iperf3 -c $SERVER -u -b 9G -t $DURATION -J > $RESULTS_DIR/udp_test.jsonParse results
echo "Results Summary:" echo "Single Stream: $(jq -r '.end.sum_received.bits_per_second' $RESULTS_DIR/single_stream.json | awk '{print $1/1000000000 " Gbps"}')" echo "Multi Stream: $(jq -r '.end.sum_received.bits_per_second' $RESULTS_DIR/multi_stream.json | awk '{print $1/1000000000 " Gbps"}')"`Example 2: Internet Service Provider Testing
Scenario: Testing customer internet connection speeds and quality.
Automated Testing Script:
`bash
#!/bin/bash
ISP Speed Test Script
ISP_SERVER="speedtest.isp.com" TEST_DURATION=30 REPORT_FILE="/tmp/isp_speed_test_$(date +%Y%m%d_%H%M%S).txt"
echo "ISP Speed Test Report - $(date)" > $REPORT_FILE echo "=================================" >> $REPORT_FILE
Download speed test
echo "Testing download speed..." | tee -a $REPORT_FILE DOWNLOAD_RESULT=$(iperf3 -c $ISP_SERVER -t $TEST_DURATION -J) DOWNLOAD_SPEED=$(echo $DOWNLOAD_RESULT | jq -r '.end.sum_received.bits_per_second') echo "Download Speed: $(echo "scale=2; $DOWNLOAD_SPEED/1000000" | bc) Mbps" | tee -a $REPORT_FILEUpload speed test
echo "Testing upload speed..." | tee -a $REPORT_FILE UPLOAD_RESULT=$(iperf3 -c $ISP_SERVER -R -t $TEST_DURATION -J) UPLOAD_SPEED=$(echo $UPLOAD_RESULT | jq -r '.end.sum_received.bits_per_second') echo "Upload Speed: $(echo "scale=2; $UPLOAD_SPEED/1000000" | bc) Mbps" | tee -a $REPORT_FILELatency and packet loss test
echo "Testing packet loss and jitter..." | tee -a $REPORT_FILE UDP_RESULT=$(iperf3 -c $ISP_SERVER -u -b 50M -t 10 -J) PACKET_LOSS=$(echo $UDP_RESULT | jq -r '.end.sum.lost_percent') JITTER=$(echo $UDP_RESULT | jq -r '.end.sum.jitter_ms') echo "Packet Loss: $PACKET_LOSS%" | tee -a $REPORT_FILE echo "Jitter: $JITTER ms" | tee -a $REPORT_FILEecho "Test completed. Report saved to $REPORT_FILE"
`
Example 3: Wireless Network Optimization
Scenario: Optimizing wireless network performance in an office environment.
Site Survey Script:
`bash
#!/bin/bash
Wireless Performance Survey
ACCESS_POINT="192.168.1.1" SURVEY_POINTS=("Conference Room" "Office Area" "Kitchen" "Reception") RESULTS_DIR="/tmp/wireless_survey"
mkdir -p $RESULTS_DIR
for location in "${SURVEY_POINTS[@]}"; do echo "Testing location: $location" echo "Please move to $location and press Enter..." read # Record signal strength SIGNAL=$(iwconfig wlan0 | grep "Signal level" | awk '{print $4}' | cut -d'=' -f2) # Test throughput THROUGHPUT_RESULT=$(iperf3 -c $ACCESS_POINT -t 30 -J) THROUGHPUT=$(echo $THROUGHPUT_RESULT | jq -r '.end.sum_received.bits_per_second') # Test UDP performance UDP_RESULT=$(iperf3 -c $ACCESS_POINT -u -b 100M -t 10 -J) PACKET_LOSS=$(echo $UDP_RESULT | jq -r '.end.sum.lost_percent') # Save results cat << EOF > "$RESULTS_DIR/${location// /_}.txt" Location: $location Signal Strength: $SIGNAL dBm Throughput: $(echo "scale=2; $THROUGHPUT/1000000" | bc) Mbps Packet Loss: $PACKET_LOSS% Test Time: $(date) EOF echo "Results for $location saved." done
Generate summary report
echo "Wireless Survey Summary" > "$RESULTS_DIR/summary.txt" echo "======================" >> "$RESULTS_DIR/summary.txt" for file in "$RESULTS_DIR"/*.txt; do if [[ "$file" != *"summary.txt" ]]; then echo "" >> "$RESULTS_DIR/summary.txt" cat "$file" >> "$RESULTS_DIR/summary.txt" fi done`Example 4: Network Monitoring and Alerting
Continuous Monitoring Script:
`bash
#!/bin/bash
Network Performance Monitor
MONITOR_SERVER="monitor.company.com" THRESHOLD_MBPS=800 CHECK_INTERVAL=300 # 5 minutes LOG_FILE="/var/log/network_monitor.log" ALERT_EMAIL="admin@company.com"
log_message() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a $LOG_FILE }
send_alert() { local message="$1" echo "$message" | mail -s "Network Performance Alert" $ALERT_EMAIL log_message "ALERT: $message" }
while true; do
log_message "Starting network performance check"
# Perform speed test
RESULT=$(iperf3 -c $MONITOR_SERVER -t 10 -J 2>/dev/null)
if [ $? -eq 0 ]; then
SPEED_BPS=$(echo $RESULT | jq -r '.end.sum_received.bits_per_second')
SPEED_MBPS=$(echo "scale=2; $SPEED_BPS/1000000" | bc)
log_message "Current speed: $SPEED_MBPS Mbps"
# Check if speed is below threshold
if (( $(echo "$SPEED_MBPS < $THRESHOLD_MBPS" | bc -l) )); then
send_alert "Network speed below threshold: $SPEED_MBPS Mbps (threshold: $THRESHOLD_MBPS Mbps)"
fi
# Check for retransmissions
RETRANSMITS=$(echo $RESULT | jq -r '.end.sum_sent.retransmits')
if [ "$RETRANSMITS" -gt 100 ]; then
send_alert "High retransmission count detected: $RETRANSMITS"
fi
else
send_alert "Network performance test failed - server unreachable"
fi
sleep $CHECK_INTERVAL
done
`
This comprehensive guide covers all aspects of using iperf3 for network performance testing, from basic installation to advanced optimization techniques and real-world implementation scenarios. The tool provides invaluable insights into network behavior and helps identify bottlenecks, optimize configurations, and validate network infrastructure performance.