Home Linux Commands How to Check Linux Network Statistics from Command Line

How to Check Linux Network Statistics from Command Line

Network Load refers to the amount of data being transferred or received over a network. Since Linux distributions are very commonly used as servers, the network load on the server becomes a topic of prominence for Linux server admins or system admins.

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

Prerequisites

The commands explained in the article can be tried out on a desktop Linux machine as well. However, you can try these with a Linux server to really get a hold of it. You can try installing Apache or Nginx servers and hosting 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 in Linux distributions by default. While the development of netstat is now at a halt, 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 its derived distributions:

$ sudo apt install net-tools

On RedHat and its derived distributions, run:

$ yum install net-tools

To get the network load overview, you can call both netstat and ss with the flag -s. netstat gives the output in more depth, while ss gives a summary of the load.

$ netstat -s
Check Linux Network Statistics
Check Linux Network Statistics

This is a shortened output displayed in the screenshot below. The TCP section will also show a summary of connections and packet transfers for UDP.

$ ss -s
Check Linux Network Connections
Check Linux Network Connections

Notice that it shows the packets by 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 which is very handy not only for network administration but also for overall system administration is the sar command, which is used for finding any kind of resource usage.

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

$ sudo apt install sysstat

In RedHat, Fedora, and other derivatives, run:

$ yum install sysstat

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

$ sudo service sysstat restart

The syntax to display network traffic with sar is:

$ sar -n Protocol Interval Repetitions

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

$ sar -n DEV 2 5
Check Network Interface Traffic
Check Network Interface Traffic

Check the load for other protocols such as TCP.

$ sar -n TCP 2 3
Check Network TCP Traffic
Check Network TCP Traffic
Conclusion

In this article, we described three commands that can be used to monitor and check the network load in Linux. Make sure you go through the command line man pages of these commands to learn in-depth about more options.

$ man netstat
$ man ss
$ man sar

Thanks for reading! Which tool do you prefer to use for checking the Linux network load? Do let us know in the comments below!

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.