How to monitor the network on Ubuntu Server 20.04

Louis SanchezJuly 29th 2021, 8:40

The Ubuntu server provides tons of utilities to ease network monitoring and administration.

Step 1 : We will start with a commonly used command, that is, ifconfig. You will need to install net-tools.

sudo apt install net-tools

We mostly use this command to read the network configuration details such as the IP address.


Step 2 : If you are only interested in quick network statistics, use ifconfig with flag -s

ifconfig -s

Step 3 : Another commonly used command is ping. It sends ICMP requests to a specified host and waits for the reply.

ping -c 5

Step 4 : Next, comes netstat. It is mainly used to check network connections and routing tables on the system.

sudo netstat -plutn

Step 5 : Another command, lsof, gives you a list of all open files. It includes the files used for network connections or sockets

sudo lsof -i

Step 6 : Next, we will look at a well-known tool, tcpdump. It collects network traffic and displays it to a standard output or dump in a file system

sudo tcpdump -i ens4

When no interface is specified, tcpdump defaults to the first configured interface

Step 7 : Next, to get statistics of network traffic, use the command sar.

sar -n ALL 1 5

Step 8 : There is one more utility named collectl. you will need to separately install this command as well:

apt install collectl

Use collectl with the -s flag and value sn to get statistics about the network.