Linux check network traffic

Monitoring Network Bandwidth and Speed in Linux

Last updated October 7, 2020 By Sergiu 25 Comments

Brief: In this article, we list some open source utilities to monitor the network traffic, bandwidth and internet speed in Linux.

Monitoring internet speed can be a crucial step in understanding your connection and it can help you find possible problems. It will also help you troubleshoot any connectivity problems you might have and find possible bottlenecks.

Tools for Monitoring Internet traffic and speed in Linux

I am going to present you different tools to help monitor your internet speed. I have provided installation instructions for Ubuntu/Debian based distributions but the tools can be easily installed in other distributions.

It doesn’t matter if you are a beginner that wants a simple, working solution, a guru looking to get as much information about your network as possible, if you prefer GUI or CLI programs, I’ll help you find the right tool for the job.

1. NetSpeed – GNOME shell extension for desktop users

NetSpeed is a GNOME shell extension that displays the sum of your download and upload speed in your gnome panel. Clicking on it displays the separate values in a drop-down.

It is applicable only if you use the GNOME desktop environment. If you are not familiar already, read this tutorial to know how to use GNOME Shell extensions.

2. Fast – Netflix’s Internet speed tester

Fast is an open-source CLI utility powered by Netflix fast.com service. Although the code for the website itself isn’t open-source, Netflix have explained how it works here. Fast is the perfect tool for someone that just wants to check the download speed in a very simple manner.

You can install it using snap. Make sure to enable Snap support in your distribution and then run the following command:

Once installed, you can run the utility by typing in:

Once again, after a few seconds, you’ll get your result:

3. speedtest-cli: check upload and download speed

speedtest-cli is an open-source command line interface for testing internet bandwidth using speedtest.net (which, itself, isn’t open-source). It is a quick little tool for checking your download and upload speed.

speedtest-cli is available in most distros and can easily be installed using the package manager. On Debian/Ubuntu, you can use the following command:

Once installed, simply run:

After a few seconds, you’ll get information about which server was used for checking your connection, as well as the details concerning your internet speed. Use man speedtest to learn about additional options (such as not performing download test with –no-download).

4. NetHogs – Check bandwidth utilization per program basis

NetHogs is a simple open-source utility that runs in the terminal. Instead of breaking the traffic down per protocol or per subnet, it groups bandwith by process. It is very helpful for finding the PID of a hanging program or just for seeing what is eating your bandwidth. It relies mostly on /proc, so most features are Linux-only.

Luckily, NetHogs is included in many distros. That means you can install and remove it using your normal package manager. On Debian/Ubuntu, you can use this:

To run it, simply use:

Читайте также:  Устройство файловой системы windows linux

Conveniently, you can specify devices after the command (such as sudo nethogs eth0). You also have additional parameters, such as choosing a delay for the refresh rate (-d), version info (-V), tracemode (-t) and a few others which you can check out in the man pages (man nethogs).

5. nload – Real-Time internet traffic monitoring

nload is an open-source console application that allows you to monitor network traffic and bandwidth usage in real time. It visualizes incoming and outgoing traffic using graphs, while also providing additional information (total amount of transferred data, min/max network usage etc.). It’s a simple to use tool that can be really helpful at times.

You can install it in Debian and Ubuntu based distributions using the command:

To run it, simpy type in:

You can control its various aspects from the manpage (man nload).

6. CBM – Color Bandwidth Meter

CBM is a very simple tool that displays (in color) network traffic on all connected devices, in a very stripped-down manner.

CBM is a slightly older piece of software that can be found in most distro repositories. This makes installing and removing it using the package manager very easy.

Using CBM is just as easy as installing it. You run:

The commands are displayed in the bottom of your terminal so that you can control them easily.

7. iPerf – Test network performance between two hosts

iPerf is tool used for network performance measurement and tuning and can produce standardized performance measurements for any network. It has client and server functionality, and can create data streams to measure bandwidth, loss and other parameters between the two ends in one or both directions. There are two implementations: the original iPerf (iPerf2) and a non-backwards compatible implementation iPerf3.

The easiest way to install (or remove) iPerf or iPerf3 is using the package manager. For example, in Ubuntu:

Then you can just run the one you want:

Note: For all further examples, if you are using iPerf3 simply replace all instances of iperf with iperf3.

However, doing so will only display your options. To run iPerf, you need a minimum of 2 machines: one to act as a client and one to act as a server. For the server, you’ll use:

This will open the machine for listening on port 5001. To connect to another machine and run a test, you’ll use:

Where server_address is, of course, the address of the server you are trying to connect to. This can be either an IP address, or something like ping.online.net. The iPerf3 team has a list of servers to use for testing purposes.

iPerf is a widely used tool that has a lot of specific uses and many options. I won’t go into those, since it is beyond the scope of this article. However, you can check out the manpage (man iperf / man iperf3) or the documentation.

8. vnStat – Network traffic logger

vnStat is an open-source console-based network traffic monitor that uses the network interface statistics provided by the kernel as information source for its periodic logs. This means that vnStat won’t actually be sniffing any traffic and also ensures light CPU usage. It can be run without root permissions.

As with many other networking tools, vnStat is include in most distribution repositories. This means you can very easily install (and remove) it using your package manager.

To use it in the most basic way, simply enter:

vnStat offers you more advanced features too, such as the ability to use databases (importing them or exporting output to a file). You can check these out in the manpage (man vnstat). More examples can be found on the official website.

9. iftop – The ‘top’ of Network Usage

iftop is a free open-source software command-line system monitor tool that produces a frequently updated list of network connections between pairs of hosts. The connections can be ordered by different parameters, but they ordered by default by bandwidth usage, with only the “top” bandwidth consumers shown.

Wrapping Up

In this article I showed you multiple tools you can use to monitor different statistics concerning the performance of your network. There is a tool that is right for everyone, and you can pick and choose the one that fits your specific needs. I hope this article was a good introduction to the world of internet monitoring.

Читайте также:  Linux show module options

What is your favorite tool and how are you using it? Let us know in the comments section!

Like what you read? Please share it with others.

Источник

5 system tools to monitor network traffic in Linux with examples

Table of Contents

How to monitor network traffic in Linux? How to monitor application network traffic real time in Linux? How to perform speed test using command line in Linux? How to monitor network speed in graphical and CLI in Linux.

We will cover these questions in this tutorial. There are multiple open source and commercial software available to monitor network traffic. but I will concentrate on the tools which are delivered as part of Linux distribution rather than third party tools.

I will be using CentOS 8 for all the demonstrations where 192.168.43.154 (server.example.com) will act as server and 192.168.43.10 (client.example.com) will act as a client. If you are on a different distribution then some of the commands and their arguments may vary.

Method 1: Check network bandwidth using iperf3

iperf3 is a tool for performing network throughput measurements. It can test TCP, UDP, or SCTP throughput. To perform an iperf3 test the user must establish both a server and a client.

You can use yum search to get the package name.

Install iperf3 on both the server and client node

On the node which will act as server I will enable port 5201 which is the default port used by iperf3 using firewalld . The port used can be changed with the -p command line option. I have intentionally not used —permanent with firewalld as I just want to allow this port for temporary session.

On the server system, iperf3 is told to listen for a client connection using iperf3 -i 5 -s :

  • -i the interval to provide periodic bandwidth updates
  • -s listen as a server

Sample output from my server. Press Ctrl+C once the client stops sending packets

iperf3 running on server

On the client node execute iperf3 -i 5 -t 60 -c

iperf3 session from the client

  • -i the interval to provide periodic bandwidth updates
  • -t the time to run the test in seconds
  • -c connect to a listening server at.

So the network throughput between my server and client was

Method 2: Network B/W and latency measurement using qperf

qperf is a network bandwidth and latency measurement tool which works over many transports including TCP/IP, RDMA, UDP, and SCTP. It is available in the RHEL and CentOS Server channel, so no third-party packages are required.

Install qperf from the on both the server and client host:

The server listens on TCP Port 19765 by default. This can be changed with the —listen_port option.

As I don’t intend to use this port, I have not used —permanent so the firewalld rule changes will not be persistent.

On server execute qperf to start receiving the packates

Simultaneously on the client execute below command to check for TCP bandwidth. Here replace 192.168.43.154 with the IP or hostname of your server where you started qperf

  • -ip use Port to run the socket tests
  • -t set test duration to Time.
  • —use_bits_per_sec use bits/sec rather than bytes/sec when displaying networking speed

Similarly we can check for TCP latency between server and client. Here the latency is 83.1 microseconds and since we have used -v the results are more detailed.

Following is the result from my client node:

qperf to monitor network latency

Method 3: Using nc or netcat with dd command

dd is in the coreutils package, and nc is in the nc package, both provided by Red Hat and CentOS default repository.

On the server enable the port which you will use to monitor the network throughput. I will use port 12345 so I have enabled it temporarily just for this session without using —permanent .

Next start a netcat listener on the server.

Simultaneously have the client connect to the listener using dd if=/dev/zero bs=1M count=10240 | nc -n 12345 .

The dd command will report throughput/second:

Читайте также:  Linux подключение сетевого сканера

Monitor network throughput with dd and nc

Method 4: Using TX and RX bytes to calculate real time network usage per interface

There are multiple system tools which gives us the TX (transfer) and RX (receive) data for individual interfaces. We can easily monitor these values to get real time network bandwidth usage details.

Output from ifconfig for eth1 interface

Content of /proc/net/dev

Output from ip command

So as you see all these commands give you the data of overall transferred and received bytes over the period of time from eth1 interface. We will use a custom script to monitor real time traffic usage on eth1 interface by using these TX and RX bytes

Here I have written a shell script which does real time monitoring of individual interface on Linux server:

We have to execute this shell script with the interface we want to monitor:

The screen will refresh every 2 second and you will get the real time network bandwidth usage on the provided interface.

Method 5: Monitor network traffic using sar

  • sar is a short term abbreviation for System Activity Report.
  • It can be used for realtime monitoring of Linux system performance.
  • The sar command writes to standard output based on the values in the count and interval parameters
  • The collected data can also be saved in the file specified by the -o filename flag, in addition to being displayed onto the screen.
  • You can select information about specific system activities using flags. Not specifying any flags selects only CPU activity.
  • The sar command extracts and writes to standard output records previously saved in a file. This file can be either the one specified by the -f flag.
  • All data is captured in binary form and saved to a file (datafile) with default location /var/log/sa/saXX where XX specified the day of the month

sar is provided as part of sysstat package. This package may not be installed by default so you can install it manually:

The syntax to be used to monitor real time network traffic per interface:

In this example we are executing sar for 10 times with an interval of 2 seconds. This gives a real time information of packets sent and received per interface. You can check man page of sar to understand about individual section

What’s Next

Conclusion

In this tutorial I have shared a list of tools and commands which can be used to monitor network traffic for individual or all the interfaces in Linux. I have tried to use only those tools which are delivered as part of default RHEL/CentOS repository and you don’t need to download or install any rpm from third party sources. The default system itself contains so many useful command for network diagnostics, although when you need more details such as historical data of network consumed by individual process then we may have to rely on third party tools.

Lastly I hope the steps from the article to monitor network traffic on Linux was helpful. So, let me know your suggestions and feedback using the comment section.

References

I have used below external references for this tutorial guide
How to test network bandwidth using system provided tools

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

5 thoughts on “5 system tools to monitor network traffic in Linux with examples”

Hello
is the great script in Method 4: available to copy/paste or download ?

I am afraid, you will have to follow the image and write the script.

Fix for the script in Method 4. On Redhat 7.6 I had some issues and the below resolved them.

Thanks for sharing. The script need RX and TX bytes data from ifconfig output and the ifconfig command output varies across distributions so one just have to have sure that awk and grep is able to capture the required data for further calculations

Источник

Оцените статью