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.
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
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
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
-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 the load for other protocols such as TCP.
$ sar -n TCP 2 3
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!