How to check Internet speed from the command line on Linux

When you are experiencing slow Internet access, you may want to test the Internet speed of your upstream ISP (often called "last mile" in the residential broadband networks) as part of troubleshooting. For that matter, Speedtest.net is probably the most widely used broadband speed testing website.

Underneath it, Speedtest.net loads JavaScript code in your web browser, which then automatically detects the closest Speedtest.net server from you, and measures download/upload speed by sending HTTP GET and POST requests to the server.

However, if you are trying to check Internet speed from a remote headless server, VPS or an otherwise desktop-less system, Speedtest.net's Flash-based user-friendly interface would be no good. For those of you, there is a command-line interface (CLI) version of Speedtest.net, known as speedtest-cli. Here I will demonstrate how to use speedtest-cli to check Internet speed from the command line in Linux.

Install speedtest-cli on Linux

speedtest-cli is a simple CLI client written in Python for measuring bidirectional Internet bandwidth by using Speedtest.net infrastructure. It works with Python 2.4-3.4. Installing the latest speedtest-cli is nothing more than downloading the Python script.

$ wget https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py
$ chmod a+rx speedtest_cli.py
$ sudo mv speedtest_cli.py /usr/local/bin/speedtest-cli
$ sudo chown root:root /usr/local/bin/speedtest-cli

Test Internet Connection Speed with speedtest-cli

It is straightforward to check your Internet speed with speedtest-cli. Running speedtest-cli command without any argument gets its job done.

$ speedtest-cli

This will automatically discover the closest Speedtest.net server (in terms of geographic distance), and report download and upload speed measured from the server.

If you want to share the speed test result, you can use "--share" option, which will allow you to share speed test result with others in an image format via Speedtest.net.

The following is a sample image automatically generated and uploaded to Speedtest.net by speedtest-cli.

If you want to get a list of available Speedtest.net servers around the world, use "--list" option. It will display a sorted list of Speedtest.net servers (geographically closest ones first).

In the server list shown above, each Speedtest.net server shows an associated server ID in front. You can manually specify server ID during testing, instead of using the geographically closest server. For example, if I want to use a sever in Washington DC, I specify a corresponding server ID (e.g., 935).

$ speedtest-cli --server 935

NOTE: Don't run any aggressive cron job! speedtest-cli is an unofficial third-party tool which is meant for residential users who want to check their broadband speed. You are NOT supposed to run any aggressive script with it. If you want to run automated bandwidth monitoring with speedtest-cli, you should set up your own Speedtest.net server with Speedtest Mini, and run any automated test against it, instead of bombarding the Speedtest.net's infrastructure which is shared with many others!

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

35 thoughts on “How to check Internet speed from the command line on Linux

  1. That's... fantastic!

    Honestly.. I use command-line versions of GUI tools (like youtube-dl, wget, lftp) to do remote grabbing. I never imagined there'd be a tool like this.

    Deffo grabbing and using. Thanks!

  2. The difference between javascript/browser and a simple fast cli is probably about 400Mb/s vs 880Mb/s (at my work). At least that's the difference between a low end pc and a 50x more expensive apple on the same line.

  3. The CLI seems to be a little slow with Google FIber compared to +900/900, ping 1ms, through the web interface with server 3280 (Google Kansas City)

    [dattaway@dattaway speedtest-cli-master]$ ./speedtest_cli.py --server 3280
    Retrieving speedtest.net configuration...
    Retrieving speedtest.net server list...
    Testing from Google Fiber (23.228.174.251)...
    Hosted by Google Fiber (Kansas City, MO) [15.95 km]: 13.669 ms
    Testing download speed........................................
    Download: 678.29 Mbit/s
    Testing upload speed..................................................
    Upload: 204.17 Mbit/s

    • You lucky guy, here is my pathetic result from India. I am one of those guys who do not bother to spend a lot for broadband in India, subscribed to a high end plan ($27 for 2Mbps 20GB cap line)
      ========================================================
      Retrieving speedtest.net configuration...
      Retrieving speedtest.net server list...
      Testing from BSNL (117.195.107.139)...
      Selecting best server based on ping...
      Hosted by Indusind Media & Communication Ltd. (Mumbai) [127.57 km]: 28.61 ms
      Testing download speed........................................
      Download: 1.21 Mbit/s
      Testing upload speed..................................................
      Upload: 0.37 Mbit/s
      ========================================================

  4. This is great.. I can set cron jobs up for checking it daily to see how it goes.

    Does anyone know of a similar test that can be done on a local network to determine speeds from a local server?
    Thanks

  5. Any ideas how to fix this:
    speedtest-cli
    Retrieving speedtest.net configuration...
    Retrieving speedtest.net server list...
    Testing from Eircom (95.44.18.130)...
    Selecting best server based on ping...
    Traceback (most recent call last):
    File "/usr/local/bin/speedtest-cli", line 655, in
    main()
    File "/usr/local/bin/speedtest-cli", line 649, in main
    speedtest()
    File "/usr/local/bin/speedtest-cli", line 560, in speedtest
    best = getBestServer(servers)
    File "/usr/local/bin/speedtest-cli", line 408, in getBestServer
    fastest = sorted(results.keys())[0]
    IndexError: list index out of range
    System -Ubuntu Trusty Tahr 14.04

  6. Nifty!

    I'd have never thought to look without this article, but gentoo already has a net-analyzer/speedtest-cli package available... and thanks to you, it's now installed. =:^)

    In case anyone is wondering (it's not clear in the article), speedtest-cli does NOT require proprietary flash or the like. It's pure python and (as the article says) works with python 2.4-3.4 according to its readme. License is Apache 2.0, so it's free software. =:^)

  7. there is no need to run wget with sudo. avoid running as root what can be done as a normal user.

    if you really want to install this system wide, i would:
    download normally:

    wget https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py
    chmod a+rx speedtest_cli.py
    sudo mv speedtest_cli.py /usr/local/bin/speedtest_cli
    sudo chown root.root /usr/local/bin/speedtest_cli

    however, for most users, it would suffice to just download and then simply run
    python speedtest_cli.py
    and get the results right there.

    no need to bother with putting it somewhere else or making it accessible to all users, because most likely you are the only user on your server, and also you don't really want to invite all users to continuously run speedtests. it's an admin tool.

  8. If you need to get an estimate from a certain server (not in your network), you can use curl:

    curl -m 10 -w '%{http_code}\n%{speed_download}\n' -o /dev/null -s url_to_file_on_server

    This will output something like this:
    200
    994271.000

    If http_code is not 200, something went wrong.
    If it is, you can devide speed_download by 1000 to get the Kb/s

    • the script is installed as root (which makes it available systemwide to all users), but run as a normal user.

      greetings, eMBee.

  9. Very interesting article; I am going to use this tool, as sometimes the browser version of Speedtest.net is slow itself because of the GUI.

  10. A more accurate speed test is to ping your ISP - Even with command line speed check you still have to pass through various nodes to get the connection and anyone of them can interfere and give a false speed check.

  11. Great post, and useful too.

    Now I have a follow-on request. Is it possible to use this cli to do periodic bandwidth tests and feed the results directly into a MySQL-type database along with a time stamp? Also the ability to specify a specific server at runtime would be great.

    The need is for a time-based bandwidth test (to run every "x" minutes, via cron) which can then be graphed to show bandwidth over time - per day/per week/per month, etc - although this would be from the database side and can be easily done as long as the data is present.

    • Some further clarification:

      We have broadband from multiple providers. Sometimes, the "speed" bounces up and down, giving varying results different from what is offered. Also we sometimes experience outages by one or the other provider, which they sometimes deny.

      This is a simple and low-cost method of tracking the provider's availability by periodically running the test (every 5, 10, 15, 20 or 30 minutes - exact interval to be determined) against each provider's connection.

      The output would then be inserted into an SQL database as a record containing: Time; Script name (this would identify the ISP being tested); Target Server; ping time; upload (in Kbps); download (in Kbps/Mbps).

      Another separate application would then process this data and generate various graphs to indicate uptimes, throughput and outages (if any).

      I am also open to comments on the practicality or sensibility of such an undertaking, and any possible improvements also..

      G. George

      • With speedtest-cli, scripting bandwidth test and storing time-series statistics in a back-end server is straightforward. My only concern is whether automated speedtest against speedtest.net infrastructure would be in violation of terms of use. Speedtest-cli is an unofficial third-party tool. You want to be cautious in running any kind of aggressive cron jobs with it. A safer way is to set up your Speedtest.net server, and test against it. They offer something called Ookla Speedtest Mini (http://www.speedtest.net/mini.php) to set up something like that.

        • I understand the issue at risk of beating up on the infrastructure of an unwilling 3-rd party. This is why i considered the option of establishing or targetting a specific server that one could conceivably set up oneself. In fact, the idea is to establish a test or reflector server (or one with multiple different and separate IP) for each provider and use forced routing rules on the testing server to achieve some form of source routing to target the separate infrastructure.

          I must look into the Ookla option, although I think I may have communicated with them previously on this matter, and if I recall correctly, their software did not support what I was trying to achieve. I'll also review my notes on this.

  12. How about using wget to download a big iso file from a fast provider like the closest to you mirror from sourceforge.net?

  13. Thanks a lot, I really needed this for testing my internet connection which seems rather unreliable.

  14. Hi, great tool ... I was looking for a long time for something like this. I'm interested to know if speedtest-cli can also be used against my own Ookla speedtest mini server.

Leave a comment

Your email address will not be published. Required fields are marked *

Current ye@r *