iperf & iperf3 Network Testing
Network bandwidth testing with iperf and iperf3. Understand differences and common usage patterns.
iperf vs iperf3
Key Differences
| Feature | iperf2 | iperf3 |
|---|---|---|
| Compatibility | Not compatible with iperf3 | Not compatible with iperf2 |
| Parallel Streams | Multiple streams in both directions | One direction at a time |
| Simultaneous Bi-directional | Yes | No (sequential only) |
| JSON Output | No | Yes |
| UDP Bandwidth | Must specify | Auto-detects |
| Active Development | Less active | Actively maintained |
| Default Port | 5001 | 5201 |
Recommendation: Use iperf3 for new projects (better maintained, JSON output, simpler).
Installation
1# Linux
2sudo apt install iperf3
3sudo apt install iperf # For iperf2
4
5# macOS
6brew install iperf3
7brew install iperf2
8
9# Windows (Scoop)
10scoop install iperf3
iperf3 Commands
Basic TCP Test
1# Server mode (run on server)
2iperf3 -s
3
4# Client mode (run on client)
5iperf3 -c server_ip
6
7# Output:
8# [ ID] Interval Transfer Bitrate
9# [ 5] 0.00-10.00 sec 1.09 GBytes 941 Mbits/sec
Test Duration
1# Test for 30 seconds (default is 10)
2iperf3 -c server_ip -t 30
3
4# Test for 60 seconds
5iperf3 -c server_ip -t 60
Parallel Streams
1# Use 4 parallel streams
2iperf3 -c server_ip -P 4
3
4# Use 10 parallel streams
5iperf3 -c server_ip -P 10
Reverse Mode
1# Server sends data to client (reverse direction)
2iperf3 -c server_ip -R
3
4# Useful for testing upload vs download speeds
UDP Testing
1# UDP test with 100 Mbps bandwidth
2iperf3 -c server_ip -u -b 100M
3
4# UDP test with 1 Gbps bandwidth
5iperf3 -c server_ip -u -b 1G
6
7# Show packet loss
8iperf3 -c server_ip -u -b 100M
9# Output includes: Jitter, Lost/Total Datagrams
Specific Port
1# Server on custom port
2iperf3 -s -p 5555
3
4# Client to custom port
5iperf3 -c server_ip -p 5555
JSON Output
1# Output results in JSON format
2iperf3 -c server_ip -J > results.json
3
4# Parse with jq
5iperf3 -c server_ip -J | jq '.end.sum_received.bits_per_second'
Interval Reporting
1# Report every 1 second (default)
2iperf3 -c server_ip -i 1
3
4# Report every 5 seconds
5iperf3 -c server_ip -i 5
6
7# No interval reports (only final)
8iperf3 -c server_ip -i 0
Bandwidth Limit
1# Limit to 10 Mbps
2iperf3 -c server_ip -b 10M
3
4# Limit to 100 Mbps
5iperf3 -c server_ip -b 100M
Bi-directional Test
1# Test both directions (sequential in iperf3)
2iperf3 -c server_ip --bidir
3
4# First tests client->server, then server->client
IPv6
1# Server with IPv6
2iperf3 -s -6
3
4# Client with IPv6
5iperf3 -c server_ipv6 -6
iperf2 Commands
Basic TCP Test
1# Server
2iperf -s
3
4# Client
5iperf -c server_ip
Simultaneous Bi-directional
1# Test both directions simultaneously (iperf2 only)
2iperf -c server_ip -d
3
4# Full duplex test
5iperf -c server_ip -r # Sequential bi-directional
Window Size
1# Set TCP window size
2iperf -c server_ip -w 256K
Common Use Cases
Test LAN Speed
1# Server
2iperf3 -s
3
4# Client (expect ~940 Mbps on gigabit ethernet)
5iperf3 -c 192.168.1.100 -t 30
Test WiFi Speed
1# Server (wired connection)
2iperf3 -s
3
4# Client (WiFi device)
5iperf3 -c server_ip -t 60 -i 1
6
7# Monitor for fluctuations in WiFi performance
Test VPN Throughput
1# Server (outside VPN)
2iperf3 -s
3
4# Client (inside VPN)
5iperf3 -c vpn_server_ip -t 30
6
7# Compare with direct connection
Test Multiple Connections
1# Simulate multiple users
2iperf3 -c server_ip -P 10 -t 60
3
4# Useful for testing router/switch capacity
Test Packet Loss (UDP)
1# Server
2iperf3 -s
3
4# Client - UDP test
5iperf3 -c server_ip -u -b 100M -t 30
6
7# Check output for packet loss percentage
8# Jitter: 0.015 ms
9# Lost/Total Datagrams: 0/75000 (0%)
Continuous Monitoring
1# Run server in background
2iperf3 -s -D
3
4# Or with systemd
5sudo systemctl start iperf3
6
7# Run periodic tests
8while true; do
9 iperf3 -c server_ip -t 10 -J >> results.log
10 sleep 300 # Every 5 minutes
11done
Docker Setup
1version: '3.8'
2
3services:
4 iperf3-server:
5 image: networkstatic/iperf3
6 container_name: iperf3-server
7 command: -s
8 ports:
9 - "5201:5201"
10 restart: unless-stopped
11
12 # Client (for testing)
13 iperf3-client:
14 image: networkstatic/iperf3
15 container_name: iperf3-client
16 command: -c iperf3-server -t 10
17 depends_on:
18 - iperf3-server
1# Run server
2docker run -d --name iperf3-server -p 5201:5201 networkstatic/iperf3 -s
3
4# Run client
5docker run --rm networkstatic/iperf3 -c host.docker.internal
Interpreting Results
TCP Results
1[ ID] Interval Transfer Bitrate Retr
2[ 5] 0.00-10.00 sec 1.09 GBytes 941 Mbits/sec 0 sender
3[ 5] 0.00-10.04 sec 1.09 GBytes 937 Mbits/sec receiver
- Transfer: Amount of data transferred
- Bitrate: Speed in Mbits/sec or Gbits/sec
- Retr: Retransmissions (should be 0 or very low)
Good Results:
- Gigabit Ethernet: ~940 Mbps (TCP overhead)
- 10 Gigabit: ~9.4 Gbps
- WiFi 5 (802.11ac): 200-600 Mbps
- WiFi 6 (802.11ax): 600-1200 Mbps
UDP Results
1[ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
2[ 5] 0.00-10.00 sec 119 MBytes 99.8 Mbits/sec 0.015 ms 0/85000 (0%)
- Jitter: Variation in packet delay (lower is better)
- Lost/Total: Packet loss (should be 0% or very low)
Good Results:
- Jitter: < 1 ms (excellent), < 10 ms (good)
- Packet Loss: 0% (excellent), < 1% (acceptable), > 5% (poor)
Troubleshooting
Low Throughput
1# Check for retransmissions
2iperf3 -c server_ip -t 30
3
4# If high retransmissions:
5# - Check network cables
6# - Check switch/router
7# - Check for interference (WiFi)
8# - Check CPU usage on both ends
9
10# Try increasing TCP window
11iperf3 -c server_ip -w 256K
12
13# Try parallel streams
14iperf3 -c server_ip -P 4
Firewall Issues
1# Allow iperf3 port
2sudo ufw allow 5201/tcp
3sudo ufw allow 5201/udp
4
5# Or iptables
6sudo iptables -A INPUT -p tcp --dport 5201 -j ACCEPT
7sudo iptables -A INPUT -p udp --dport 5201 -j ACCEPT
Connection Refused
1# Check if server is running
2ps aux | grep iperf
3
4# Check if port is listening
5netstat -tuln | grep 5201
6ss -tuln | grep 5201
7
8# Test connectivity
9ping server_ip
10telnet server_ip 5201
Automation Script
1#!/bin/bash
2# iperf3-test.sh - Automated network testing
3
4SERVER="192.168.1.100"
5DURATION=30
6OUTPUT_DIR="./iperf_results"
7
8mkdir -p $OUTPUT_DIR
9
10# TCP Test
11echo "Running TCP test..."
12iperf3 -c $SERVER -t $DURATION -J > $OUTPUT_DIR/tcp_$(date +%Y%m%d_%H%M%S).json
13
14# UDP Test
15echo "Running UDP test..."
16iperf3 -c $SERVER -u -b 100M -t $DURATION -J > $OUTPUT_DIR/udp_$(date +%Y%m%d_%H%M%S).json
17
18# Parallel streams
19echo "Running parallel streams test..."
20iperf3 -c $SERVER -P 4 -t $DURATION -J > $OUTPUT_DIR/parallel_$(date +%Y%m%d_%H%M%S).json
21
22# Reverse test
23echo "Running reverse test..."
24iperf3 -c $SERVER -R -t $DURATION -J > $OUTPUT_DIR/reverse_$(date +%Y%m%d_%H%M%S).json
25
26echo "Tests complete. Results in $OUTPUT_DIR"
Quick Reference
1# Server
2iperf3 -s # Start server
3
4# Basic tests
5iperf3 -c server_ip # TCP test
6iperf3 -c server_ip -u -b 100M # UDP test
7iperf3 -c server_ip -R # Reverse (server to client)
8iperf3 -c server_ip -P 4 # 4 parallel streams
9
10# Advanced
11iperf3 -c server_ip -t 60 # 60 second test
12iperf3 -c server_ip -J # JSON output
13iperf3 -c server_ip -i 5 # Report every 5 seconds
14iperf3 -c server_ip -p 5555 # Custom port
Related Snippets
- DNS Fundamentals & Configuration
DNS fundamentals and practical configuration for common services like Gmail and … - iftop - Network Bandwidth Monitor
Real-time network bandwidth monitoring with iftop. Basic Usage Monitor Default … - NATS Setup with JWT Authorization
NATS server setup and JWT-based authorization cheatsheet - Performance Measurement Tools
Essential tools for measuring network and computer performance. Quick reference … - Security Essentials & Best Practices
Security best practices, OWASP Top 10, secure coding practices, and security … - Serial Port Sniffing
Tools and techniques for capturing and analyzing serial port communication … - tcpdump - Packet Capture
Packet capture and analysis with tcpdump. Essential tool for network debugging … - WireGuard VPN Setup
WireGuard VPN setup with port forwarding and tunneling. Modern, fast, and secure …