- How to get network interface speed programactically on Linux?
- 2 Answers 2
- How to Test Network Speed in Linux via CLI
- Test Network Speed on Linux Via Command Line
- Using speedtest-cli to Test Internet Speed
- Using fast-cli to Test Internet Speed
- Using CMB to Show Network Speed
- Using iperf to Measure Network Speed Between Two Devices
- Using nload to View Incoming and Outgoing Network Traffic
- Using tcptrack to Test Network Activity
- Using iftop to Test Speed on a Network Interface
- Using wget to Test Download Speed
- Using youtube-dl to Test Internet Speed
- How can I verify the speed of my NIC in ubuntu?
- 3 Answers 3
- How do I Check my NIC Speed in Linux?
- Different Methods of Checking the NIC Speed in Linux
- Method # 1: Making Use of the “ethtool”
- Method # 2: Making Use of the “dmesg” Command
- Method # 3: Making Use of the “mii-tool”
- Conclusion
- About the author
- Karim Buzdar
How to get network interface speed programactically on Linux?
I am wondering about the speed as show in the network connection information, e.g. 100Mb/s, 10Mb/s, not the available bandwidth. Thanks in advance!
2 Answers 2
If you want to do that in C code, look up mii-tool.c
Information is done via quering the appropriate ioctl function and mii-tool.c provides example of that.
programatically read this info and parse it, looking for 100baseTx or similar
# mii-tool -v eth0 eth0: negotiated 100baseTx-FD flow-control, link ok product info: vendor 00:00:20, model 32 rev 1 basic mode: autonegotiation enabled basic status: autonegotiation complete, link ok capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
also, on same article you could use this and look for the «speed:» line
#ethtool eth0 Settings for eth0: Supported ports: [ TP MII ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Advertised auto-negotiation: Yes Speed: 100Mb/s Duplex: Full Port: MII PHYAD: 32 Transceiver: internal Auto-negotiation: on Supports Wake-on: pumbg Wake-on: p Current message level: 0x00000007 (7) Link detected: yes
How to Test Network Speed in Linux via CLI
With the increase in people staying at home and spending more time on the Internet, ISPs have seen traffic loads higher than ever. If you noticed your network speed was slower at times, this global overload is the reason.
There are many online tools to test internet speed. However, Linux users can do this from the command prompt window. Some of the utilities for testing both local and internet speed we will cover are:
- Speedtest
- Fast
- Color Bandwidth Meter (CBM)
- iPerf
- nload
- Tcptrack
- Iftop
- Wget
- youtube-dl
Follow the instructions in this article to learn how to test network connection speed on Linux using the terminal. The steps work in both normal and headless mode.
- A machine running Linux
- sudo / root permissions
- Access to a terminal / command-prompt window
Test Network Speed on Linux Via Command Line
The tools in this guide help you check the Internet and LAN speed on a Linux machine. The article uses Ubuntu 20.04 for instructions, but the utilities work for any Linux distribution.
Note: Use the appropriate package manager for your Linux distribution, for example, yum for RHEL / CentOS, to install the apps.
Using speedtest-cli to Test Internet Speed
One of the most famous online internet connection test apps is speedtest.net. To install Speedtest on Linux via the terminal, use a package manager for your distro.
sudo apt install speedtest-cli
Optionally, use pip to install speedtest-cli in Python:
sudo pip install speedtest-cli
The standard speedtest-cli output shows all steps, including selecting a server. To display a shorter output, enter:
The test is simple to use and provides multiple options. To view all of them, pass the -h flag to display the speedtest-cli help file.
Using fast-cli to Test Internet Speed
Fast is a lightweight CLI utility based on the web speed test fast.com. The test uses Netflix servers to provide results.
Fast-cli is simple to use, but you need the node package manager (NPM) on your machine. The package comes with Nodejs.
For example, to install Node.js version 15, enter these commands:
curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -
Then, run the install command:
sudo apt install -y nodejs
If needed, run the npm init command and then install Fast:
npm install --global fast-cli
To test the download speed, enter:
To show both the download and upload speed, add the -u option:
This internet speed test aims to provide only the information about your connection speed, without any bells and whistles.
Note: Since NPM is a requirement, it can be a hassle to install fast-cli. If you need more help with NPM installation, see our guides How To Install Node.Js And NPM On CentOS or How To Install Node.Js & NPM On Ubuntu.
Using CMB to Show Network Speed
The Color Bandwidth Meter (CMB) is a Linux tool that displays activity on all network interfaces. After the installation, run the tool to see network speeds in color-coded columns.
To install CBM, run this command:
When the process finishes, run the tool:
The output displays the transmit, receive, and total speed. Use the arrows to switch between the interfaces.
Using iperf to Measure Network Speed Between Two Devices
The iPerf tool provides many options for testing connection speed between a server and a client. Hence, to perform a test, you need to install the utility on both machines:
Make sure the client can reach the server. For quick confirmation, run a ping test.
If port 5001 is open, the connection works. So, on the server machine, enter:
The device starts listening for a connection request.
On the other machine, enter:
The output shows the transfer and bandwidth information:
Using nload to View Incoming and Outgoing Network Traffic
Nload is a tool that monitors incoming and outgoing activity on a network interface you specify. The application splits the traffic into two sections for easier data analysis.
To install the tool, enter:
To run the application, specify the network interface:
If there is activity on the selected interface, nload displays network speed details.
Using tcptrack to Test Network Activity
TCPtrack shows the connection status for a network interface. When your machine’s network is active, run this tool to view and monitor bandwidth speed and usage.
To install tcptrack on Linux Ubuntu, enter:
sudo apt install tcptrack
To view network activity with TCPtrack, specify the network interface. To find the device name, use the ifconfig tool.
In our case, it is enp0s3
The terminal displays the network activity on the selected interface. The total network speed is at the bottom of the terminal:
Note: Make sure you run tcptrack with sudo . Otherwise, this error pops up: pcap_open_live: enp0s3: You don’t have permission to capture on that device (socket: Operation not permitted)
TCPtrack is customizable and offers options to narrow down the test to specific ports, for example.
To do so, pass the port option and the port number:
sudo tcptrack -i enp0s3 port 443
If there is no activity on the port, the output is blank.
Using iftop to Test Speed on a Network Interface
Iftop lets you view network speed for a defined interface. The tool shows a similar output to what tcptrack provides.
To install iftop, run this command:
To launch the utility, use the -i flag and specify your network interface.
In our case:
The output shows the activity for the device. The bottom of the screen provides a traffic summary.
If you do not specify a network interface, iftop selects the first available. Make sure you run the command with sudo to avoid any errors.
Using wget to Test Download Speed
Wget is a CLI tool for downloading content from web servers. Since the tool does not upload files, you can only test the download speed.
If you do not have wget on your Ubuntu machine, enter this command to install it:
Now, choose a reliable server to download a file and test your internet speed. For example, use phoenixNAP’s 1GB test file from the list.
This example uses a server located in Phoenix:
wget -O /dev/null -q --show-progress http://174.138.175.114/PHX-1GB.test
Using youtube-dl to Test Internet Speed
An unconventional way to test your download speed is to use the youtube-dl CLI utility. The tool allows you to download YouTube videos and view the download speed.
To install youtube-dl, enter:
sudo apt install youtube-dl
The application takes around 268MB of space. While the installation is in progress, choose a video you want to download and save the URL.
When the process finishes, use this command but replace the URL with the one you selected:
youtube-dl -f best --no-part --no-cache-dir -o /dev/null --newline https://www.youtube.com/watch?v=8TLsqgLDMN4
The terminal shows the download progress, file size, download speed, and ETA.
The command above does not save the file to any filesystem, hence the /dev/null part.
This example used a short phoenixNAP BMC demo video of around 19MB. Choose a longer video for more precise results.
The article showed you nine ways to test network speed in Linux via CLI. Choose the tool depending on whether you want to test local network speed, internet speed, etc.
The tools work for all Linux distributions, so make sure you use the right package manager.
How can I verify the speed of my NIC in ubuntu?
Is there a command that I can verify by its output the speed of my NIC and some information about its characteristics such as duplex full or half .
3 Answers 3
Suppose your NIC name eth0 :
You can verify the speed and some informations by three Commands :
First Command :
Second Command :
FD : full duplex , Logic that enables concurrent sending and receiving. This is usually desirable and enabled when your computer is connected to a switch.
HD : half duplex , his logic requires a card to only send or receive at a single point of time. When your machine is connected to a Hub, it auto-negotiates itself and uses half duplex to avoid collisions.
Third command :
ethtool eth0 ethtool - Display or change ethernet card settings
sudo apt-get install ethtool
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
How do I Check my NIC Speed in Linux?
“We all know that a network interface card (NIC) acts as a bridge between a computer system and the network that this system is attached. The NIC has an associated speed which determines the quality of your interaction with the network. Therefore, in this guide, we will try to explore the methods through which we can check the NIC speed in Linux.”
Different Methods of Checking the NIC Speed in Linux
There are different methods of checking the network interface card (NIC) speed on a Linux system that is discussed below:
Method # 1: Making Use of the “ethtool”
In the first method, we will be using the “ethtool” utility for checking the NIC speed. However, if this utility is not already installed on your Linux system, then you will have to install it first with the following command:
Once you have this utility installed on your system, you need to check the interface name of the network interface whose speed you wish to find out. For that, you will have to run the command given below:
This command will display the information about all the network interfaces of your system, as shown in the following image. We have picked up the network interface named “enp0s3” for demonstrating this method as well as the other two methods.
Now, to check the speed of the specified NIC, we will execute the command shown below:
The speed of our specified NIC is highlighted in the following image:
However, you can see that the output of the above-mentioned command is a bit too lengthy. Therefore, if you wish to confine this output to the NIC speed only, then you will have to modify it in the manner shown below:
You can visualize from the following output that now, only the NIC speed appears on the terminal.
Method # 2: Making Use of the “dmesg” Command
In this method, we will use the built-in “dmesg” command in Linux to check the NIC speed as shown below:
The speed of the specified NIC is highlighted in the following image:
Method # 3: Making Use of the “mii-tool”
Now, we will use the “mii-tool” utility to check the NIC speed in Linux. This utility resides inside the “net-tools” package; therefore, we will install it first with the command shown below:
After installing this package on your system, you will have to run the following command to check the NIC speed:
The speed of the specified NIC of our Linux system is highlighted in the image shown below:
Conclusion
With the help of this useful guide, you can instantly learn three different methods of checking the NIC speed in Linux. After learning these methods, it is entirely a matter of your own choice which method you choose to follow to suffice your need.
About the author
Karim Buzdar
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.