- For a quick download figure, curl needs no installing:
curl -o /dev/null -w '%{speed_download}\n' <url>prints bytes per second. - Multiply bytes per second by 8 and divide by 1,000,000 to get megabits per second, the unit your provider quotes.
- speedtest-cli gives you the familiar Ookla download, upload and ping figures on a server with no desktop.
- iperf3 is the only one of the three that measures the link between two machines you control, with no third-party server in the way.
- A slow result is often latency or a slow test server, not bandwidth. Test more than one destination before you raise a ticket.
How do I run a speed test from the Linux terminal?
Use curl, which is already installed on nearly every Linux server. Point it at a large test file, throw the download away, and ask curl to print the transfer rate. It needs nothing installed and works over SSH on a server with no desktop. For upload, ping and server-to-server tests, use speedtest-cli or iperf3.
curl -o /dev/null -w 'Speed: %{speed_download} bytes/sec\n' \
'https://speed.cloudflare.com/__down?bytes=100000000'That prints bytes per second. Internet connections are sold in megabits per second, so pipe the result through awk to get the unit in your contract.
curl -s -o /dev/null -w '%{speed_download}\n' \
'https://speed.cloudflare.com/__down?bytes=100000000' \
| awk '{printf "%.2f Mbit/s\n", $1 * 8 / 1000000}'Quote the URL
The test URL contains a question mark and often an ampersand. Without single quotes, your shell tries to interpret them, and the command either runs in the background or fails.
How do I test upload speed with curl?
People forget upload, but it matters when you send backups offsite or serve a busy site. Create a file of known size, POST it, and read the speed_upload figure. Delete the file afterwards.
# 1. Create a 50 MB file of zeroes
dd if=/dev/zero of=/tmp/uptest bs=1M count=50
# 2. Upload it and print the rate
curl -s -o /dev/null -w '%{speed_upload}\n' \
-X POST --data-binary @/tmp/uptest \
https://speed.cloudflare.com/__up \
| awk '{printf "Upload: %.2f Mbit/s\n", $1 * 8 / 1000000}'
# 3. Clean up
rm /tmp/uptestCheck you have the disk space first
On a small server with a nearly full disk, dd will fill the last free gigabyte and take the site down with it. Run df -h /tmp before you create the file. How to check CPU, memory and disk usage shows how to see how much room you have.
What do the curl timing variables tell me?
This is where curl beats a browser speed test. The same -w flag shows each stage of the request separately, so you can see whether a slow page is DNS, the connection, the TLS handshake (setting up encryption), or the server working out its reply. That last one is Time to First Byte, and it is usually the number that matters.
curl -s -o /dev/null -w '\
DNS lookup: %{time_namelookup}s\n\
TCP connect: %{time_connect}s\n\
TLS handshake: %{time_appconnect}s\n\
First byte: %{time_starttransfer}s\n\
Total: %{time_total}s\n\
Download speed: %{speed_download} bytes/sec\n' \
https://example.com/| Variable | What it measures | What a bad number means |
|---|---|---|
| time_namelookup | Turning the hostname into an IP address | Slow or distant DNS resolver, or no local cache |
| time_connect | Opening the connection to the server | Network distance or a congested link |
| time_appconnect | Setting up TLS encryption | Slow certificate chain or an old TLS version |
| time_starttransfer | Time to first byte: the server working | The application or database is slow, not the network |
| time_total | The whole request | Compare with first byte to see if the page body is the problem |
Reading the stages separately turns "the site feels slow" into a specific thing to fix.
If time_starttransfer is over a second but time_connect is fast, more bandwidth will not help: the server is slow, not the connection. That is a hosting or application problem, and our WordPress performance page covers the server side of it.
How do I install and use speedtest-cli?
speedtest-cli gives you the familiar Ookla figures (download, upload and ping) against a nearby test server it picks for you. It is a Python tool, so you need to install it, but it is the closest terminal match to what people mean by a speed test.
# Debian / Ubuntu
sudo apt update && sudo apt install -y speedtest-cli
# AlmaLinux / Rocky / CentOS Stream (needs EPEL)
sudo dnf install -y epel-release
sudo dnf install -y speedtest-cli
# Any distribution with pip
pip3 install --user speedtest-cli# Full test
speedtest-cli
# Just the numbers, no progress output
speedtest-cli --simple
# Report in bytes rather than bits
speedtest-cli --bytes
# Pick a specific test server
speedtest-cli --list | head -20
speedtest-cli --server 12345--simple in scripts and cron jobs: three lines of output, nothing to strip out.The automatic server choice is not always the best one
speedtest-cli picks the server with the lowest ping, which is often a small regional host that cannot fill a gigabit port. If your result looks low, run speedtest-cli --list, pick a large, well-connected provider, and test again with --server.
When should I use iperf3 instead?
curl and speedtest-cli both measure the path to someone else's server. iperf3 measures the path between two machines you control. Use it to test a link between two of your own servers, or to show a provider that a specific route is slow.
# Install on both machines
sudo apt install -y iperf3 # Debian / Ubuntu
sudo dnf install -y iperf3 # AlmaLinux / Rocky
# On the receiving machine, start a listener
iperf3 -s
# On the sending machine
iperf3 -c 203.0.113.10
# Test the reverse direction (server sends to client)
iperf3 -c 203.0.113.10 -R
# Four parallel streams, which is closer to how real traffic behaves
iperf3 -c 203.0.113.10 -P 4| Tool | Measures | Needs installing | Best for |
|---|---|---|---|
| curl | Download, upload and per-stage timings | No | A quick check, and finding where the time goes |
| speedtest-cli | Download, upload, ping to a public server | Yes | A number you can compare with a home broadband test |
| iperf3 | Throughput between two machines you own | Yes, on both ends | Showing a specific route or link is underperforming |
Choose by what you need to prove, not by which is quickest to type.
Why is my server speed test slower than I expected?
Most disappointing results are not a bandwidth problem. Before you open a ticket, rule out these four causes, in this order. They explain most slow results.
- 1One connection cannot fill a fast link over a long distance. A single stream to a server 5,000 miles away levels off well below your port speed, however good the network. Test again with
iperf3 -P 4or against a closer server before you decide anything. - 2The test server is the bottleneck. Public test files are shared with everyone else testing at that moment. Run the same command against two or three destinations. If one is slow and the others are fine, that server was the problem.
- 3Your server is busy. A machine already maxing out its CPU on PHP, or its disk on a database query, has nothing left to drive the network. Check the load first with top, htop and the standard resource commands.
- 4Something else is using the link. A backup, a large rsync or a busy site will eat the bandwidth you are trying to measure. nload shows live traffic in and out, so you can see the baseline before your test starts.
Test more than once, at more than one time of day
A single result is an anecdote. Run the test three times over a few hours and write the numbers down. A link that is fast at 6am and slow at 8pm is congested at busy times, which is a different conversation with a provider from a link that is always slow.
If the bandwidth is fine but pages are still slow, the network was never the issue. Visitors feel the server's response time, which depends on CPU, database and caching, not bandwidth. Core Web Vitals for WordPress explains which measurement matters for which symptom.
How do I log speed test results over time?
One measurement tells you almost nothing. A week of them tells you whether the problem is constant, tied to busy times, or a one-off. A three-line cron job (a scheduled task) is enough.
# Log download speed in Mbit/s every hour, with a timestamp
0 * * * * root curl -s -o /dev/null -w '%{speed_download}\n' \
'https://speed.cloudflare.com/__down?bytes=25000000' \
| awk -v d="$(date -Is)" '{printf "%s %.2f\n", d, $1*8/1000000}' \
>> /var/log/speedtest.logAdd the log to logrotate so it cannot grow forever. Linux system logs and where to find them covers rotation and where everything lives.
Frequently asked questions
Can curl really measure internet speed accurately?
Yes, for download and upload, as long as the file is large enough (50 MB or more) and the test server is not itself the bottleneck. curl cannot pick a good nearby server for you, which is what speedtest-cli adds. For a single number, use speedtest-cli; to find where the time goes, curl's timing variables are better.
Why does curl report speed in bytes per second and not megabits?
curl reports bytes because that is what it moved. Providers quote megabits. To convert, multiply bytes per second by 8 and divide by 1,000,000, so 12,500,000 bytes/sec is 100 Mbit/s. Piping the output through awk, as shown above, does the sum for you.
How do I run a speed test on a server with no internet-facing access?
Use iperf3 between the server and another machine on the same network or private link. It needs no outside server, so it works on isolated machines. Start iperf3 -s on one machine and iperf3 -c <ip> on the other.
Does a speed test tell me if my website is slow?
Rarely. Bandwidth almost never limits a normal website: a page is a few hundred kilobytes and the connection moves that in milliseconds. What visitors feel is Time to First Byte, which comes down to CPU, database and caching. Use curl's time_starttransfer figure for that, not speed_download.
Is speedtest-cli still maintained?
The original Python speedtest-cli is still packaged by every major distribution and still works. Ookla also publish an official tool called speedtest, which supports more servers and reports more detail. Either is fine for a terminal test; the Python one is easier to install from your distribution's repositories.
About G7Cloud Engineering
Articles written by the engineers who build and run G7Cloud: UK managed hosting and the AI Website Builder. We write about what we operate every day: containers, backups, databases, and the small-business websites that run on them.
More about G7Cloud →