How to check Linux network statistics from the command line

by time news

Network load refers to the amount of data that is transferred or received over a network. Since Linux distributions are very often used as servers, the network load on the server becomes a major issue for Linux system or server administrators.

Basically, it is about how the bandwidth is used in the network; how many packets are being sent/received, and so on. Today, let us find out how we can check the network load on a Linux server.

previous requirements

The commands explained in the article can also be tested on a desktop Linux machine. However, you can try them with a Linux server to really get a handle on it. You can try to install servers Apache o Nginx and host a sample website on them.

Check Linux network load using Netstat and SS commands

Netstat is a popular command for everything related to network analysis. It is not available on Linux distributions by default. Although the development of netstat it is now stopped, it is replaced by the command ss which is available by default in Ubuntu , CentOS etc.

To install netstat run the following on Debian and their derived distributions:

$ sudo apt install net-tools

In RedHat and its derived distributions, run:

$ yum install net-tools

For an overview of the network load, you can call both a netstat as a ss with the mark -s. netstat gives the output with more depth, while ss gives a summary of the load.

$ netstat -s

Check Linux network statistics

This is an abbreviated output shown in the following screenshot. The section TCP it will also display a summary of connections and packet transfers for UDP.

$ss -s

Check Linux network connections

Note that it shows the packets for each protocol ( TCP , UDP ), and at the top shows the summary of connections; established, closed, etc.

Check Linux Network Resource Usage With Sar Command

Another command that is very useful not only for network administration but also for general system administration is the sar command which is used to find any type of resource usage.

To install the sar command in Debian , Ubuntu or other derivatives, use:

$ sudo apt install sysstat

In RedHat , Fedora and other derivatives, run:

$ sudo yum install sysstat

Once you have installed the command, run the following to enable the command to capture statistics.

$ sudo service sysstat restart

The syntax for displaying network traffic with sar es:

$ sar -n Repeticiones de intervalo de protocolo

Here, -n means we are calling sar for network statistics and the ‘ Protocol ‘ can be IP, TCP, UDP, DEV (which shows the traffic for each network interface like Ethernet or Wifi), etc.

$ sar -n DEV 2 5

Check network interface traffic

Check the load of other protocols like TCP.

$ sar -n TCP 2 3

Check network TCP traffic

Conclusion

In this article, we describe three commands that can be used to monitor and verify network load on Linux. Be sure to review the command line man pages for these commands for more information on more options.

$ man netstat
$ man ss
$ man sar

Thank you for reading! Which tool do you prefer to use to check Linux network load? Let us know in the comments below!

You may also like

Leave a Comment