Speedtest CLI On Linux: A Quick Guide

by Jhon Lennon 38 views

Hey guys! Ever wondered how to quickly check your internet speed directly from your Linux terminal? Well, you're in luck! This guide will walk you through using the Speedtest CLI (Command Line Interface) on Linux. It's super handy for those times when you don't want to open a browser or need to run speed tests as part of a script. Let's dive in!

What is Speedtest CLI?

Speedtest CLI is the command-line version of the popular Speedtest.net service. Instead of using a web browser, you can run speed tests directly from your terminal. This is particularly useful for Linux users who prefer working with the command line, system administrators who need to automate speed tests, or anyone who wants a lightweight and efficient way to check their internet speed. The Speedtest CLI provides accurate and reliable results, mirroring those you'd get from the web interface. Plus, it's scriptable, meaning you can integrate it into your own scripts for automated monitoring or troubleshooting. This tool is incredibly versatile and a must-have for any Linux enthusiast or professional.

Imagine you're troubleshooting a network issue on a server. Instead of opening a browser (which might not even be available), you can simply run speedtest in the terminal. The CLI will then connect to the nearest Speedtest server and perform a download and upload speed test. It displays the results directly in the terminal, including ping, download speed, upload speed, and the server location. This allows you to quickly identify whether the server's internet connection is performing as expected, making it an indispensable tool for system administrators. Moreover, you can customize the tests with various options, such as specifying a particular server or changing the test duration, providing even more control over the process. The Speedtest CLI truly brings the power of Speedtest.net to your command line, making it an efficient and practical solution for all your speed testing needs.

And the best part? It's open source and actively maintained, ensuring you get the latest features and bug fixes. Using the command line interface not only provides convenience but also enables a level of precision and automation that a graphical interface simply can't match. For instance, you can set up a cron job to run a speed test every hour and log the results, allowing you to track your internet performance over time and identify any recurring issues. You can also use the Speedtest CLI in conjunction with other command-line tools to create powerful diagnostic scripts. Whether you're a seasoned Linux pro or just starting out, the Speedtest CLI is a valuable tool to have in your arsenal, offering a quick, reliable, and scriptable way to measure your internet speed directly from the terminal.

Installing Speedtest CLI on Linux

Okay, let's get down to business! Installing Speedtest CLI on Linux is pretty straightforward. I'll cover the most common methods to get you up and running in no time. We'll look at using package managers like apt, yum, and dnf, as well as manual installation for those who prefer it. So, grab your terminal and let's get started!

Using apt (Debian/Ubuntu)

If you're on a Debian-based system like Ubuntu, you can use apt to install Speedtest CLI. First, you'll need to update your package list:

sudo apt update

Then, install the speedtest-cli package:

sudo apt install speedtest-cli

That's it! apt will handle the installation, and you'll be ready to run speed tests.

Using yum (CentOS/RHEL)

For CentOS or Red Hat Enterprise Linux, you can use yum. First, you might need to enable the EPEL repository if you don't have it already:

sudo yum install epel-release

Then, install Speedtest CLI:

sudo yum install speedtest-cli

yum will take care of the dependencies and install the CLI for you.

Using dnf (Fedora)

If you're using Fedora, dnf is your go-to package manager. Simply run:

sudo dnf install speedtest-cli

dnf will handle the installation process, and you'll be all set.

Manual Installation

If you prefer a manual installation or your distribution doesn't have a package, you can download the Speedtest CLI directly from the official website. Here’s how:

  1. Download the Speedtest CLI: Go to the official Speedtest CLI download page and grab the appropriate binary for your architecture (32-bit or 64-bit).

  2. Extract the Archive: Once downloaded, extract the archive to a directory of your choice.

  3. Move the Binary: Move the extracted binary to a directory in your system's PATH, such as /usr/local/bin/:

sudo mv speedtest /usr/local/bin/ ``` 4. Make it Executable: Ensure the binary is executable:

```bash

sudo chmod +x /usr/local/bin/speedtest ```

Now, you should be able to run speedtest from any terminal window. Manual installation gives you more control over the process, but it requires a bit more effort. Make sure you download the correct version for your system architecture to avoid any compatibility issues.

Running Speedtest CLI

Alright, now that you've got Speedtest CLI installed, let's run some tests! This is where the magic happens. I'll show you the basic command and some useful options to customize your tests. Get ready to see your internet speed in action!

Basic Speed Test

The simplest way to run a speed test is to just type speedtest in your terminal and hit enter:

speedtest

This command will connect to the nearest Speedtest server and perform a download and upload speed test. The results will be displayed directly in your terminal, including your ping, download speed, and upload speed. It's quick, easy, and gives you a snapshot of your current internet performance.

Useful Options

Speedtest CLI comes with several options that allow you to customize your tests. Here are some of the most useful ones:

  • --server [server_id]: Specify a server to use for the test. You can find a list of server IDs using the --list option.
  • --list: List available Speedtest servers. This is handy for finding a server close to you or one that you trust.
  • --bytes: Display speeds in bytes instead of bits. This can be useful if you're more familiar with byte-based measurements.
  • --simple: Suppress verbose output and only show essential information. This is great for scripting.
  • --share: Generate and display a shareable URL of the test results. This allows you to easily share your results with others.

Examples

Here are a few examples of how to use these options:

  • List available servers:

speedtest --list ```

This will display a list of Speedtest servers along with their IDs, distances, and ping times. You can use this information to choose a specific server for your test.
  • Test with a specific server:

speedtest --server 1234 ```

Replace `1234` with the ID of the server you want to use. This can be useful if you want to test your connection to a specific location.
  • Display results in bytes:

speedtest --bytes ```

This will show the download and upload speeds in bytes instead of bits. Some people find this easier to understand.
  • Simple output:

speedtest --simple ```

This will display only the ping, download speed, and upload speed, without any extra information. This is great for scripting or when you just want the essential results.
  • Share results:

speedtest --share ```

This will generate a shareable URL that you can send to others. They can then view the full test results in their browser.

Using these options, you can tailor your speed tests to your specific needs and get the information you're looking for. Experiment with different options to see what works best for you. And remember, the more you use Speedtest CLI, the more comfortable you'll become with its capabilities.

Automating Speed Tests

Now, let's talk about automating Speed Tests. This is where things get really interesting. Imagine setting up a script to automatically run a speed test every day and log the results. This can be incredibly useful for monitoring your internet performance over time and identifying any recurring issues. I'll show you how to do it using cron, a powerful task scheduler in Linux.

Using cron

cron is a time-based job scheduler in Unix-like operating systems. It allows you to schedule commands or scripts to run automatically at specific times, dates, or intervals. To use cron, you'll need to edit the crontab file, which is a table of commands scheduled to run on a regular basis.

Editing the Crontab

To edit the crontab file, use the following command:

crontab -e

This will open the crontab file in a text editor. If it's your first time using cron, you might be asked to choose an editor. Select your favorite (like nano or vim).

Crontab Syntax

The crontab file consists of lines, each representing a scheduled task. The syntax for each line is as follows:

minute hour day month weekday command
  • minute: The minute of the hour when the command should run (0-59).
  • hour: The hour of the day when the command should run (0-23).
  • day: The day of the month when the command should run (1-31).
  • month: The month of the year when the command should run (1-12).
  • weekday: The day of the week when the command should run (0-6, where 0 is Sunday).
  • command: The command to execute.

For example, to run a speed test every day at 6:00 AM, you would add the following line to your crontab file:

0 6 * * * speedtest --simple >> /home/user/speedtest.log 2>&1

Let's break this down:

  • 0 6 * * *: This specifies that the command should run at 6:00 AM every day.
  • speedtest --simple: This is the command to run, which is the Speedtest CLI with the --simple option to suppress verbose output.
  • >> /home/user/speedtest.log: This redirects the output of the command to a log file. Replace /home/user/speedtest.log with the path to your desired log file.
  • 2>&1: This redirects any error messages to the same log file.

Saving the Crontab

After adding your scheduled task, save the crontab file. If you're using nano, press Ctrl+X, then Y to save, and then Enter. If you're using vim, press Esc, then type :wq and press Enter.

Example Scripts

Here's a more advanced example that includes a timestamp in the log file:

0 6 * * * date +"%Y-%m-%d %H:%M:%S" >> /home/user/speedtest.log && speedtest --simple >> /home/user/speedtest.log 2>&1

This script will first add a timestamp to the log file, followed by the output of the Speedtest CLI. This makes it easier to track when each test was run.

You can also create a separate script file and schedule that with cron. For example, create a file named speedtest_script.sh with the following content:

#!/bin/bash

date +"%Y-%m-%d %H:%M:%S" >> /home/user/speedtest.log
speedtest --simple >> /home/user/speedtest.log 2>&1

Make the script executable:

chmod +x /home/user/speedtest_script.sh

Then, schedule the script to run with cron:

0 6 * * * /home/user/speedtest_script.sh

Automating speed tests with cron allows you to monitor your internet performance over time without any manual intervention. This can be incredibly useful for identifying trends, troubleshooting issues, and ensuring you're getting the speeds you're paying for.

Troubleshooting

Even with a straightforward tool like Speedtest CLI, you might run into some snags. Don't worry, I've got you covered! Here are some common issues and how to troubleshoot them. Let's get those speed tests running smoothly!

Command Not Found

If you get a