How to check if a network interface speed is set in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check the speed of a network interface in Linux. We will explore three common methods to achieve this.

First, you will use the ethtool command, a powerful utility for querying and controlling network settings. Next, you will learn how to identify your network interface using the ip link show command. Finally, we will demonstrate how to inspect the network interface speed by examining the contents of the /sys/class/net directory.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/RemoteAccessandNetworkingGroup(["Remote Access and Networking"]) linux(("Linux")) -.-> linux/PackagesandSoftwaresGroup(["Packages and Softwares"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/RemoteAccessandNetworkingGroup -.-> linux/ip("IP Managing") linux/PackagesandSoftwaresGroup -.-> linux/apt("Package Handling") subgraph Lab Skills linux/cat -.-> lab-558737{{"How to check if a network interface speed is set in Linux"}} linux/ip -.-> lab-558737{{"How to check if a network interface speed is set in Linux"}} linux/apt -.-> lab-558737{{"How to check if a network interface speed is set in Linux"}} end

Check speed with ethtool

In this step, we will learn how to check the speed of your network interface using the ethtool command. ethtool is a command-line utility for querying and controlling network driver and hardware settings.

First, let's identify your network interface. In most Linux environments, the primary network interface is often named eth0 or something similar like enpXsY. You can usually find the name by looking at the output of the ip link show command, which we will explore in the next step. For now, let's assume your interface is named eth0.

To check the speed of the eth0 interface, open your terminal and type the following command:

sudo ethtool eth0

Press Enter.

You will see output similar to this:

Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: d
        Wake-on: d
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes

Look for the line that starts with Speed:. This line tells you the current speed of your network connection. In the example above, the speed is 1000Mb/s.

If you receive an error like command not found, it means ethtool is not installed. You can install it using the package manager:

sudo apt update
sudo apt install ethtool -y

After installation, try the sudo ethtool eth0 command again.

Remember to replace eth0 with the actual name of your network interface if it's different.

Click Continue to proceed to the next step.

In the previous step, we used ethtool to check the network speed, assuming the interface name was eth0. However, network interface names can vary. In this step, we'll use the ip link show command to list all network interfaces and verify their status.

The ip command is a powerful utility for network configuration in Linux. The link object is used to manage network interfaces, and the show action displays information about them.

Open your terminal and type the following command:

ip link show

Press Enter.

You will see output similar to this, listing your network interfaces:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff

In this output:

  • lo is the loopback interface, used for communication within the same machine.
  • eth0 is likely your primary network interface connected to the external network. The name might be different in other environments (e.g., enp3s0).
  • <BROADCAST,MULTICAST,UP,LOWER_UP> indicates the state and capabilities of the interface. UP means the interface is active.
  • mtu is the Maximum Transmission Unit.
  • state UP confirms the interface is operational.

Identify the name of your primary network interface from the output. It's usually the one that is UP and not lo. In our LabEx environment, it is eth0.

Now you know how to find the correct network interface name, which is crucial for using commands like ethtool.

Click Continue to move on.

Inspect speed in /sys/class/net

In addition to using commands like ethtool, you can also find information about network interfaces directly in the Linux filesystem, specifically within the /sys directory. The /sys filesystem provides an interface to kernel data structures.

Network interface information is typically located under /sys/class/net/. Inside this directory, you'll find subdirectories named after each network interface on your system (e.g., eth0, lo).

To find the speed information for your primary interface (which we identified as eth0 in the previous step), you can look inside the /sys/class/net/eth0/speed file.

Open your terminal and use the cat command to view the content of this file:

cat /sys/class/net/eth0/speed

Press Enter.

You should see a single number as the output, representing the link speed in megabits per second (Mb/s).

1000

This output confirms the speed of the eth0 interface is 1000 Mb/s, matching the information we saw with ethtool.

This method of checking the speed by reading a file in /sys is useful because it doesn't require installing any extra tools like ethtool. It's a direct way to access information that the kernel makes available.

Remember that the path /sys/class/net/eth0/speed assumes your network interface is named eth0. If your interface has a different name, you would replace eth0 with the correct name.

You have now learned three different ways to get information about your network interfaces and their speed!

Click Continue to complete this lab.

Summary

In this lab, we learned how to check the speed of a network interface in Linux using three different methods. We first utilized the ethtool command, a powerful utility for querying and controlling network settings, to directly display the interface speed. We then explored the ip link show command to identify the network interface name, which is crucial for using tools like ethtool. Finally, we discovered how to inspect the /sys/class/net directory, a part of the sysfs virtual filesystem, to find the interface speed information by examining the contents of the speed file within the interface's directory. These methods provide different ways to access and verify the network interface speed, offering flexibility depending on the situation and available tools.