How to test network speed in Linux
How to Test Network Speed in Linux
Network speed testing is a crucial skill for Linux system administrators, developers, and power users who need to monitor their internet connection performance, troubleshoot connectivity issues, or verify network infrastructure capabilities. Whether you're diagnosing slow downloads, optimizing server performance, or simply curious about your connection speed, Linux offers numerous built-in and third-party tools to measure network performance accurately.
This comprehensive guide will walk you through various methods to test network speed in Linux, from simple command-line tools to advanced network monitoring solutions. We'll cover both upload and download speed testing, bandwidth monitoring, and real-time network analysis techniques suitable for beginners and intermediate users.
Understanding Network Speed Metrics
Before diving into testing methods, it's important to understand key network performance metrics:
- Bandwidth: The maximum data transfer rate of your connection
- Throughput: The actual data transfer rate achieved
- Latency: The time delay between sending and receiving data
- Packet Loss: The percentage of data packets that fail to reach their destination
- Jitter: Variation in latency over time
These metrics help paint a complete picture of your network performance beyond simple speed measurements.
Method 1: Using Speedtest-CLI
Installation
Speedtest-CLI is one of the most popular command-line tools for testing internet speed. It's the official command-line client from Ookla, the company behind Speedtest.net.
Ubuntu/Debian:
```bash
sudo apt update
sudo apt install speedtest-cli
```
CentOS/RHEL/Fedora:
```bash
sudo yum install speedtest-cli
or for newer versions
sudo dnf install speedtest-cli
```
Using pip (universal method):
```bash
pip install speedtest-cli
```
Basic Usage
Run a basic speed test:
```bash
speedtest-cli
```
This command will automatically select the best server and display results showing:
- Download speed
- Upload speed
- Ping/latency
Advanced Options
List available servers:
```bash
speedtest-cli --list
```
Test with a specific server:
```bash
speedtest-cli --server 12345
```
Get results in different formats:
```bash
JSON format
speedtest-cli --json
CSV format
speedtest-cli --csv
Simple output (speeds only)
speedtest-cli --simple
```
Share results:
```bash
speedtest-cli --share
```
Example Output
```
Retrieving speedtest.net configuration...
Testing from Internet Provider (123.456.789.0)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Example ISP (City, Country) [15.23 km]: 25.123 ms
Testing download speed................
Download: 85.67 Mbit/s
Testing upload speed..................
Upload: 42.34 Mbit/s
```
Method 2: Using Fast-CLI (Netflix's Speed Test)
Fast-CLI is Netflix's speed testing tool that measures your connection speed to Netflix servers.
Installation
```bash
npm install --global fast-cli
```
Or using snap:
```bash
sudo snap install fast
```
Usage
Basic speed test:
```bash
fast
```
Include upload speed:
```bash
fast --upload
```
Get single-line output:
```bash
fast --single-line
```
JSON output:
```bash
fast --json
```
Method 3: Using Wget for Download Speed Testing
Wget is a built-in tool available on most Linux distributions that can be used for basic download speed testing.
Testing Download Speed
```bash
wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test100.zip
```
For a more readable output with progress:
```bash
wget --progress=bar --show-progress -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test100.zip
```
Testing with Different File Sizes
```bash
10MB file
wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test10.zip
100MB file
wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test100.zip
1GB file
wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test1000.zip
```
Method 4: Using cURL for Speed Testing
cURL provides detailed timing information and can be used for both download and upload speed testing.
Download Speed Test
```bash
curl -o /dev/null -s -w "%{time_total} seconds, %{speed_download} bytes/sec\n" http://speedtest.wdc01.softlayer.com/downloads/test100.zip
```
Advanced cURL Speed Test
Create a script for comprehensive speed testing:
```bash
#!/bin/bash
echo "Testing download speed with cURL..."
curl -o /dev/null -s -w "Time: %{time_total}s\nSpeed: %{speed_download} bytes/sec\nSize: %{size_download} bytes\n" http://speedtest.wdc01.softlayer.com/downloads/test100.zip
```
Upload Speed Test with cURL
```bash
Create a test file
dd if=/dev/zero of=testfile bs=1M count=10
Upload test (replace with actual upload endpoint)
curl -F "file=@testfile" -s -w "Upload time: %{time_total}s\nUpload speed: %{speed_upload} bytes/sec\n" http://httpbin.org/post
```
Method 5: Using Iperf3 for Network Performance Testing
Iperf3 is a powerful tool for measuring network bandwidth between two hosts.
Installation
Ubuntu/Debian:
```bash
sudo apt install iperf3
```
CentOS/RHEL/Fedora:
```bash
sudo yum install iperf3
```
Server-Client Testing
On the server machine:
```bash
iperf3 -s
```
On the client machine:
```bash
iperf3 -c server_ip_address
```
Advanced Iperf3 Options
Test for specific duration:
```bash
iperf3 -c server_ip -t 30
```
Test with multiple parallel streams:
```bash
iperf3 -c server_ip -P 4
```
UDP testing:
```bash
iperf3 -c server_ip -u
```
Bidirectional testing:
```bash
iperf3 -c server_ip --bidir
```
Method 6: Monitoring Real-time Network Usage
Using nethogs
Nethogs shows network usage per process:
```bash
sudo apt install nethogs
sudo nethogs
```
Using iftop
Iftop displays bandwidth usage on network interfaces:
```bash
sudo apt install iftop
sudo iftop
```
Using nload
Nload provides a simple real-time network traffic monitor:
```bash
sudo apt install nload
nload
```
Method 7: Using Bandwhich for Process-specific Monitoring
Bandwhich is a modern terminal bandwidth utilization tool:
Installation
```bash
Download from GitHub releases
wget https://github.com/imsnif/bandwhich/releases/download/0.20.0/bandwhich-v0.20.0-x86_64-unknown-linux-musl.tar.gz
tar -xzf bandwhich-v0.20.0-x86_64-unknown-linux-musl.tar.gz
sudo mv bandwhich /usr/local/bin/
```
Usage
```bash
sudo bandwhich
```
Creating Automated Speed Test Scripts
Basic Speed Test Script
Create a script to regularly monitor your connection:
```bash
#!/bin/bash
speedtest-logger.sh
LOG_FILE="/var/log/speedtest.log"
DATE=$(date '+%Y-%m-%d %H:%M:%S')
echo "Running speed test at $DATE" >> $LOG_FILE
speedtest-cli --simple >> $LOG_FILE
echo "----------------------------------------" >> $LOG_FILE
```
Make it executable and add to crontab:
```bash
chmod +x speedtest-logger.sh
crontab -e
Add line: 0 /6 /path/to/speedtest-logger.sh
```
Advanced Monitoring Script
```bash
#!/bin/bash
comprehensive-network-test.sh
OUTPUT_DIR="/var/log/network-tests"
mkdir -p $OUTPUT_DIR
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
Speedtest
echo "Running Speedtest..."
speedtest-cli --json > "$OUTPUT_DIR/speedtest_$TIMESTAMP.json"
Fast.com test
echo "Running Fast.com test..."
fast --json > "$OUTPUT_DIR/fast_$TIMESTAMP.json"
Ping test
echo "Running ping test..."
ping -c 10 8.8.8.8 > "$OUTPUT_DIR/ping_$TIMESTAMP.txt"
echo "Tests completed. Results saved in $OUTPUT_DIR"
```
Troubleshooting Network Speed Issues
Common Issues and Solutions
1. Inconsistent Speed Results
- Run multiple tests at different times
- Test with different servers/endpoints
- Check for background processes consuming bandwidth
2. Slow Speeds Despite Good Internet Plan
- Check DNS settings: `sudo systemctl restart systemd-resolved`
- Test wired vs wireless connections
- Update network drivers
- Check for interference on wireless connections
3. Command Not Found Errors
- Ensure tools are properly installed
- Check if tools are in your PATH
- Try alternative installation methods
Network Interface Diagnostics
Check network interface status:
```bash
ip addr show
ifconfig
ethtool eth0 # Replace eth0 with your interface
```
Check network statistics:
```bash
cat /proc/net/dev
ss -tuln
netstat -i
```
DNS Performance Testing
Test DNS resolution speed:
```bash
dig google.com
nslookup google.com
time dig google.com
```
Best Practices for Network Speed Testing
1. Test Consistency
- Run tests at different times of day
- Perform multiple tests and average results
- Test both download and upload speeds
2. Eliminate Variables
- Close unnecessary applications
- Use wired connections when possible
- Test from different devices
- Clear browser cache and temporary files
3. Document Results
- Keep logs of speed tests over time
- Note any changes in network configuration
- Record environmental factors (weather, peak usage times)
4. Use Multiple Testing Methods
- Combine different tools for comprehensive testing
- Verify results across different servers
- Test both local network and internet speeds
Advanced Network Performance Analysis
Using ss (Socket Statistics)
Monitor active connections:
```bash
ss -tuln # Show listening ports
ss -tp # Show processes using sockets
ss -s # Show summary statistics
```
Network Latency Analysis
Continuous ping monitoring:
```bash
ping -i 0.5 8.8.8.8 | while read line; do echo "$(date): $line"; done
```
MTR (My Traceroute) for path analysis:
```bash
sudo apt install mtr
mtr google.com
```
Packet Capture Analysis
Use tcpdump for detailed packet analysis:
```bash
sudo tcpdump -i any -w capture.pcap
```
Security Considerations
When testing network speed, keep these security aspects in mind:
- VPN Impact: VPN connections typically reduce speed
- Firewall Settings: Ensure testing tools can access required ports
- Public Networks: Be cautious when testing on public WiFi
- Data Usage: Large speed tests consume significant bandwidth
Conclusion
Testing network speed in Linux offers multiple approaches, from simple command-line tools to comprehensive monitoring solutions. The choice of method depends on your specific needs: quick speed checks, continuous monitoring, or detailed network analysis.
Start with basic tools like speedtest-cli or fast-cli for general speed testing, then progress to advanced tools like iperf3 for detailed network performance analysis. Regular monitoring using automated scripts helps identify patterns and potential issues before they impact productivity.
Remember that network speed testing is just one aspect of network performance. Combine speed tests with latency measurements, packet loss analysis, and bandwidth monitoring for a complete picture of your network health. This comprehensive approach enables better troubleshooting, capacity planning, and overall network optimization.
By mastering these Linux network speed testing techniques, you'll be well-equipped to diagnose connectivity issues, optimize network performance, and ensure reliable internet access for your systems and applications.