In this tutorial, we show you in detail how you can monitor the bandwidth of the network in Linux using the iftop command in real time.
The iftop command offers us a continuous and interactive view of the network traffic that passes through a network interface in the selected Linux distribution.
Through this tutorial, we will see how to install iftop and thus manage the bandwidth of the network.
Step 1: Install Dependencies
For iftop to work in an ideal way we must have the following dependencies:
libpcap: It is a library that allows you to capture live network data.
libncurses: It is a programming library that provides an API to build text-based interfaces in a manner independent of the terminal.
To install these dependencies, we will execute the following. Enter the letter S to confirm the download and installation of the dependency packages.
sudo apt install libpcap0.8 libpcap0.8-dev libncurses5 libncurses5-dev (Debian & Ubuntu) yum -y install libpcap libpcap-devel ncurses ncurses-devel (CentOS & RHEL) dnf -y install libpcap libpcap-devel ncurses ncurses-devel (Fedora 22 & superior)
Step 2: Download & Install IFTOP
Iftop is available in official Debian and Ubuntu software repositories, so this can be installed using the apt command like this:
sudo apt install iftop
For CentOS and RedHat, it will be necessary to enable the EPEL repository and then proceed with its installation by executing the following:
yum install epel-release yum install iftop
In the Fedora distribution, iftop is also available from the default system repositories so that we can use the following command:
dnf install iftop
For Other Linux distributions, we can download Iftop using the wget command and execute some lines in the following way:
wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz tar -zxvf iftop-0.17.tar.gz cd iftop-0.17 ./configure make make install
Step 3: Use IFTOP
Once iftop is installed, we can go to the console and run the iftop command without any argument to see the bandwidth usage of the default interface like this:
In the case of having more open connections, we will see the following.
We can see detailed information of all the packages that are being sent and received.
Step 4. Monitor Network Interface
For this, we must know what interface is used, and for this, we can execute any of the following lines:
sudo ifconfig sudo ip addr show
sudo apt install net-tools
With these interfaces, we can use the -i parameter to specify the interface that we are going to monitor.
For example, with the following command we will monitor the bandwidth on the Ethernet interface on the computer:
sudo iftop -i enp0s3
If we wish to disable searches of hostnames, we can use the -n flag:
sudo iftop -n eth0
To activate the display of the used port, we must add the -P parameter:
sudo iftop -P
In this way, the iftop command is a great ally to manage in real time all the bandwidth in our network and be a support for the management tasks that are necessary to perform.