Are you looking to precisely measure your internet connection's performance without relying on graphical interfaces? A command line speed test offers a powerful, scriptable, and often more reliable way to get accurate download and upload speed data. This method is a favorite among system administrators, developers, and power users who need to monitor network health, troubleshoot connectivity issues, or integrate speed testing into automated workflows.
Unlike web-based speed test tools, which can sometimes be influenced by browser overhead or server load variations, a command-line approach often speaks more directly to your network interface. This guide will walk you through why you might choose a command line speed test, the best tools available, how to use them effectively, and how to interpret the results. We'll cover everything from simple checks to advanced scripting, ensuring you can diagnose and understand your network performance like a pro.
Why Opt for a Command Line Speed Test?
When it comes to understanding your internet speed, the immediate thought for many is a web-based tool like Speedtest.net. While these are excellent for quick, everyday checks, they have limitations. A speedtest cmd offers several distinct advantages, making it a valuable tool in the arsenal of anyone who relies on stable and fast network connectivity.
Firstly, automation and scripting are paramount. Imagine needing to monitor your home or office network's performance over 24 hours or testing speeds from multiple servers automatically. Web-based tools are cumbersome for this. Command-line tools, however, are built for it. You can easily integrate them into shell scripts, cron jobs, or other automation frameworks to run tests at regular intervals, log the data, and even trigger alerts if speeds drop below a certain threshold. This is invaluable for proactive network management.
Secondly, reduced overhead and consistency. Graphical interfaces and web pages add their own processing load. When you run a speed test from the command line, you're stripping away that extra layer. This can lead to more accurate readings, especially on systems with limited resources or when diagnosing subtle performance bottlenecks. The consistency of a command-line tool also means you're less likely to be affected by temporary browser glitches or server-side variations that can sometimes plague web interfaces.
Thirdly, remote access and headless environments. Many servers and network devices operate without a graphical desktop (headless). For these systems, or when you're accessing your network remotely via SSH, a command-line speed test is often the only feasible option. It allows you to perform essential diagnostics directly from your terminal, no matter where you are or what kind of machine you're connected to.
Finally, scriptability for developers and sysadmins. For developers building applications that rely on network performance, or system administrators managing infrastructure, the ability to programmatically test speeds is crucial. Whether it's for testing API response times under load or ensuring that a server's outbound connection is performing as expected, command-line tools provide the necessary programmatic access.
Top Tools for Command Line Speed Testing
Several excellent utilities allow you to conduct a command line speed test. The best choice often depends on your operating system, specific needs, and preference for features. Here are some of the most popular and effective options:
Speedtest-CLI (Python)
Perhaps the most well-known and widely used command-line speed test utility is speedtest-cli, a Python application that leverages the Speedtest.net infrastructure. It's versatile, available on most operating systems, and offers a good balance of features and ease of use.
Installation:
- Debian/Ubuntu:
sudo apt update && sudo apt install speedtest-cli - Fedora:
sudo dnf install speedtest-cli - macOS (using Homebrew):
brew install speedtest-cli - Windows (using Chocolatey):
choco install speedtest-cli - Directly with pip:
pip install speedtest-cli(Ensure Python and pip are installed)
Basic Usage:
To perform a standard speed test and get results: speedtest-cli
This command will automatically find the closest server, perform download and upload tests, and display the results in megabits per second (Mbps), along with ping times.
Key Features and Options:
- Specify a server: You can choose a specific Speedtest.net server by its ID or name. First, find available servers with
speedtest-cli --list. Then, usespeedtest-cli --server <server_id>. - Share results: Use
speedtest-cli --shareto generate a URL for sharing your results. This is equivalent to clicking the share button on the web interface. - Output in JSON: For scripting and programmatic parsing, use
speedtest-cli --json. This outputs detailed results in a machine-readable format. - Ping only:
speedtest-cli --bytesshows results in Bytes (useful for some calculations) instead of bits. - Upload/Download only:
speedtest-cli --uploadorspeedtest-cli --downloadto test only one direction. - No-upload:
speedtest-cli --no-uploadto test only download speed.
Example: To run a test and share the results:
speedtest-cli --share
Example: To get JSON output for scripting:
speedtest-cli --json
iperf3
iperf3 is a powerful, open-source tool for active network performance measurements. Unlike speedtest-cli, which tests against public servers, iperf3 is designed for testing between two endpoints that you control. This makes it ideal for testing the throughput of a specific link, diagnosing issues within your local network, or testing bandwidth between two servers.
How it Works:
iperf3 operates in a client-server model. You need to run iperf3 in server mode on one machine and in client mode on another. This allows you to measure the performance of the connection between those two machines.
Installation:
- Debian/Ubuntu:
sudo apt update && sudo apt install iperf3 - Fedora:
sudo dnf install iperf3 - macOS (using Homebrew):
brew install iperf3 - Windows: Download from the official iperf website or use a package manager like Chocolatey.
Basic Usage:
- On the Server Machine:
Start
iperf3in server mode:
iperf3 -s ``` This will listen for incoming client connections on the default port (5201).
- On the Client Machine:
Run
iperf3to connect to the server machine. Replace<server_ip_address>with the IP of the machine runningiperf3 -s.
iperf3 -c
This will perform a 10-second test of simultaneous bidirectional bandwidth, displaying the results for both upload and download.
Key Features and Options:
- TCP vs. UDP: By default,
iperf3uses TCP. To test with UDP, use the-uflag. - Bandwidth (UDP): When using UDP (
-u), you can specify a target bandwidth with the-bflag (e.g.,iperf3 -c <server_ip_address> -u -b 100Mfor 100 Mbps). - Duration: Change the test duration from the default 10 seconds using the
-tflag (e.g.,iperf3 -c <server_ip_address> -t 30for 30 seconds). - Parallel Streams: Test with multiple parallel streams using the
-Pflag to saturate links (e.g.,iperf3 -c <server_ip_address> -P 4). - Reverse Test: Test download by initiating the test from the server:
iperf3 -s -Ron the server, theniperf3 -c <server_ip_address> -Ron the client. - Interval: Set the reporting interval in seconds using
-i. - Output in JSON:
iperf3 --jsonfor machine-readable output.
Example: Testing UDP bandwidth between two servers:
- Server:
iperf3 -s - Client:
iperf3 -c <server_ip> -u -b 500M -t 20(Tests for 20 seconds at 500 Mbps UDP bandwidth)
iperf3 is invaluable for network engineers and anyone needing to stress-test specific network paths or configurations.
Speedtest-CLI Alternative: CLI Tools for Specific Providers
While speedtest-cli is versatile, some users may prefer tools that interact with specific provider infrastructure or offer different testing methodologies. For instance, some ISPs might offer their own command-line tools for testing their service.
- ISP-specific tools: Always check your Internet Service Provider's documentation. They might offer specific diagnostic tools, sometimes even command-line based, for troubleshooting their service.
- Other public testing platforms: While less common, other speed testing services may have their own CLI clients. Researching these is often provider- or use-case specific.
For most general purposes, speedtest-cli and iperf3 are the go-to solutions, covering public internet speed tests and private network throughput testing, respectively.
Performing Your Command Line Speed Test: Step-by-Step
Let's get practical. Here’s how you’d typically perform a command line speed test, focusing on speedtest-cli for its broad applicability to public internet speeds.
Step 1: Installation (If Not Already Done)
As detailed in the tool descriptions above, ensure you have your chosen tool installed. For speedtest-cli on a Debian-based system, this is usually:
sudo apt update && sudo apt install speedtest-cli
Step 2: Running a Basic Test
Open your terminal or command prompt. Navigate to a directory where you want to run commands (though for speedtest-cli, the location doesn't critically matter). Then, simply type:
speedtest-cli
What to Expect:
The tool will first search for the nearest Speedtest.net servers. It will then perform a ping test to determine latency to several servers and select the best one. Following that, it will conduct the download test, followed by the upload test. Finally, it will display your results, typically including:
- Ping: The latency to the server (in ms).
- Download: Your download speed (in Mbps).
- Upload: Your upload speed (in Mbps).
Look for something like this in your output:
Retrieving speedtest.net configuration...
Testing from Your ISP (XX.XX.XX.XX)...
Selecting best server based on ping...
Hosted by Server Provider (City) [XX.XX km]: XX.XX ms
Testing download speed...
Download: XX.XX Mbit/s
Testing upload speed...
Upload: XX.XX Mbit/s
Step 3: Interpreting Your Results
Ping (Latency): Lower is better. For general internet use, <50ms is good. For online gaming or real-time applications, <20ms is often ideal. High ping means delays in communication, which can make real-time interactions feel laggy.
Download Speed: This is how fast you can receive data from the internet. This is crucial for streaming, downloading files, and browsing websites. Your advertised internet plan speed is typically the maximum download speed you should expect under ideal conditions.
Upload Speed: This is how fast you can send data to the internet. Important for video calls, uploading files, streaming your own content, and online gaming. Upload speeds are often significantly lower than download speeds on consumer internet plans.
Units: The results are usually in Megabits per second (Mbps). Be aware that 1 Byte = 8 Bits. So, if a file is 100 MB (Megabytes), it would take approximately 800 Megabits to download.
Step 4: Advanced Usage (Scripting and Sharing)
For more robust testing, you'll want to use the advanced options:
- Share your results:
speedtest-cli --share
This command will output a URL where your test results are displayed graphically online, making it easy to share with your ISP or colleagues.
* **Get machine-readable output:**
```bash
speedtest-cli --json
This is gold for scripting. The output will be a JSON object containing all the details of your test, which you can then parse in a script to log data, compare over time, or set up alerts.
A sample JSON output might look like this:
```json
{
"download": {"bandwidth": 88888888, "unit": "bps", "latency": 15.5},
"upload": {"bandwidth": 44444444, "unit": "bps", "latency": 20.2},
"server": {"url": "http://example.com/speedtest/upload.php", "lat": "34.0522", "lon": "-118.2437", "name": "Los Angeles", "country": "United States", "cc": "US", "sponsor": "Example ISP", "distance": 5.23, "latency": 15.5, "id": "1234"},
"timestamp": "2023-10-27T10:30:00Z",
"bytes_sent": {"value": 100000000, "unit": "B"},
"bytes_received": {"value": 200000000, "unit": "B"},
"client": {"ip": "XX.XX.XX.XX", "isp": "Your ISP", "country": "US"}
}
```
Note that `bandwidth` in JSON is often in bits per second (bps), so you'll need to divide by 1,000,000 (or 10^6) to get Mbps. The `unit` field clarifies this.
Automating Tests: You can combine
speedtest-cli --jsonwith a scripting language like Bash or Python to run tests periodically. For example, in Bash, you could usecronto schedule a script that runsspeedtest-cli --json, parses the output, and appends the data to a log file.#!/bin/bash RESULT=$(speedtest-cli --json) TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") DOWNLOAD=$(echo $RESULT | jq '.download.bandwidth') UPLOAD=$(echo $RESULT | jq '.upload.bandwidth') PING=$(echo $RESULT | jq '.server.latency') echo "$TIMESTAMP,$((DOWNLOAD/1000000)),$((UPLOAD/1000000)),$PING" >> speed_log.csv(This script assumes
jqis installed for easy JSON parsing. You would divide by 1,000,000 to get Mbps from bps.)
Common Issues and Troubleshooting
When performing a cmd speed test, you might encounter a few common issues:
Inaccurate Results:
- Server Choice: The default server selection might not be optimal. Try specifying a server closer to your physical location using
speedtest-cli --listandspeedtest-cli --server <server_id>. - Background Activity: Other devices or applications on your network might be consuming bandwidth. Ensure no large downloads, uploads, or streaming services are running during the test.
- Wi-Fi vs. Ethernet: A wired Ethernet connection is generally more stable and provides more accurate results than Wi-Fi. If possible, connect directly via Ethernet for critical tests.
- Router/Modem Issues: Reboot your router and modem. Sometimes a simple restart can resolve performance bottlenecks.
- ISP Throttling: Some ISPs may throttle speeds during peak hours or for certain types of traffic. Running tests at different times of day can reveal this.
- Server Choice: The default server selection might not be optimal. Try specifying a server closer to your physical location using
Tool Not Found: Ensure the tool is correctly installed and its executable path is in your system's PATH environment variable. If you installed via pip, you might need to run it as
python -m speedtest_clior ensure~/.local/binis in your PATH.Firewall Blocking: Firewalls (on your local machine or network) can sometimes interfere with speed test connections. Ensure the ports used by the testing tool are open.
Permission Denied: If you're on Linux/macOS and get permission errors, you might need to use
sudofor installation or execution, though running the speed test itself usually doesn't require root privileges.
When to Use iperf3 vs. speedtest-cli
Use
speedtest-cliwhen:- You want to measure your internet connection speed to external servers (e.g., your connection to the general internet).
- You need to test from public infrastructure like Speedtest.net.
- You want to quickly check your internet speed from anywhere with internet access.
Use
iperf3when:- You want to measure the maximum throughput between two specific devices (e.g., your laptop and a server on your local network, or two cloud servers).
- You are troubleshooting local network performance (LAN/WAN).
- You need to test with specific protocols (TCP/UDP) or custom bandwidth settings.
- You are testing a specific link or connection path, not your overall internet gateway.
FAQ: Command Line Speed Test Questions
What is the best command line speed test tool? For general internet speed testing,
speedtest-cliis highly recommended due to its ease of use and reliance on the widely recognized Speedtest.net infrastructure. For testing network throughput between specific points,iperf3is the standard. The "best" tool depends on your specific goal.How do I get my internet speed in Mbps from the command line? Most tools, like
speedtest-cli, will output speeds in Mbps by default. If a tool outputs in bits per second (bps), you will need to divide the value by 1,000,000 (or 10^6) to convert it to Mbps. Check theunitfield in JSON outputs.Can I run a command line speed test on Windows? Yes.
speedtest-clican be installed on Windows via Chocolatey (choco install speedtest-cli) or by using pip.iperf3is also available for Windows and can be downloaded from its official website.Is a command line speed test more accurate than a website? Often, yes. Command-line tools have less overhead than web browsers. They can also be less susceptible to certain network conditions or server load variations that might affect graphical web interfaces. However, the accuracy ultimately depends on the tool, the servers it uses, and your local network environment.
How often should I run a command line speed test? For general monitoring, running tests daily or weekly can be beneficial. For troubleshooting, run tests as needed when you suspect an issue. For critical applications, consider setting up automated tests to run hourly or even more frequently, logging the data for trend analysis.
Conclusion
Mastering the command line speed test empowers you with precise control over network diagnostics. Whether you're using the versatile speedtest-cli to gauge your connection to the wider internet or the powerful iperf3 to benchmark specific network paths, these tools offer invaluable insights. By integrating them into your workflow, you can proactively monitor performance, efficiently troubleshoot issues, and ensure your network infrastructure is operating at its peak. Don't let network performance be a black box – bring it into the light with the command line.



