How to install iftop and use it on Linux Mint 18.3

To install iftop and use it on Linux Mint 18.3

Iftop command, which referes to Interface TOP, is a real time console-based network bandwidth monitoring tool that shows a quick overview of network activities on an interface. It displays a real time updated list of network usage bandwidth every 2, 10 and 40 seconds on average. It is really so simple to install iftop and use it on Linux Mint 18.3 and this tutorial covers the ground on the same process.

Installing iftop

First, before you begin with the actual installation, you are required to install a few library packages which are very essential for this process.

Linuxhelp ~ # apt install libpcap0.8 libpcap0.8-dev libncurses5 libncurses5-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libncurses5 is already the newest version (6.0+20160213-1ubuntu1).
libpcap0.8 is already the newest version (1.7.4-2).
The following additional packages will be installed:
  libtinfo-dev
Suggested packages:
  ncurses-doc
.
.
Setting up libtinfo-dev:amd64 (6.0+20160213-1ubuntu1) ...
Setting up libncurses5-dev:amd64 (6.0+20160213-1ubuntu1) ...
Setting up libpcap0.8-dev (1.7.4-2) ...

Once it is done, you need to download and install iftop. Iftop is available in the official software repositories of Debian/Ubuntu Linux, so you can install it using apt command but in this tutorial, we are installing it using source through wget utility in the following manner.

linuxhelp ~ # wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz
--2018-03-06 00:34:53--  http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz
Resolving www.ex-parrot.com (www.ex-parrot.com)... 93.93.130.166, 2a00:1098:0:82:1000:0:1:2
Connecting to www.ex-parrot.com (www.ex-parrot.com)|93.93.130.166|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 160381 (157K) [application/gzip]
Saving to: ‘ iftop-0.17.tar.gz’ 

iftop-0.17.tar.gz                    100%[===================================================================> ] 156.62K  --.-KB/s    in 0.003s  

2018-03-06 00:34:54 (44.0 MB/s) - ‘ iftop-0.17.tar.gz’  saved [160381/160381]


Now, extract the package by making use of the following command.

linuxhelp ~ # tar -zxvf iftop-0.17.tar.gz
iftop-0.17/
iftop-0.17/aclocal.m4
iftop-0.17/addr_hash.c
iftop-0.17/addr_hash.h
iftop-0.17/addrs_dlpi.c
iftop-0.17/addrs_ioctl.c
iftop-0.17/AUTHORS
iftop-0.17/bootstrap
iftop-0.17/cfgfile.c
iftop-0.17/cfgfile.h
.
.
iftop-0.17/ui.h
iftop-0.17/util.c
iftop-0.17/vector.c
iftop-0.17/vector.h


Once it is done, you need to navigate to the iftop folder and list all the files.

linuxhelp ~ # cd iftop-0.17/
linuxhelp iftop-0.17 #
inuxhelp iftop-0.17 # ls
aclocal.m4     cfgfile.c     COPYING      hash.c      INSTALL       NEWS       resolver.c      sorted_list.c  TODO
addr_hash.c    cfgfile.h     dlcommon.c   hash.h      integers.h    ns_hash.c  resolver.h      sorted_list.h  token.h
addr_hash.h    ChangeLog     dlcommon.h   iftop.8     ip.h          ns_hash.h  screenfilter.c  stringmap.c    ui.c
addrs_dlpi.c   config        edline.c     iftop.c     llc.h         options.c  screenfilter.h  stringmap.h    ui.h
addrs_ioctl.c  config.h.in   ether.h      iftop.cat   Makefile.am   options.h  serv_hash.c     tcp.h          util.c
AUTHORS        configure     ethertype.h  iftop.h     Makefile.in   ppp.h      serv_hash.h     threadprof.c   vector.c
bootstrap      configure.in  extract.h    iftop.spec  Makefile.OLD  README     sll.h           threadprof.h   vector.h

You shall now execute the configuration script.

linuxhelp iftop-0.17 # ./configure 
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets ${MAKE}... yes
checking for gcc... gcc
.
.
config.status: creating Makefile
config.status: creating config/Makefile
config.status: creating config.h
config.status: executing depfiles commands

You shall now install it by making use of the make command

linuxhelp iftop-0.17 # make
make  all-recursive
make[1]: Entering directory ' /home/user/iftop-0.17' 
Making all in config
make[2]: Entering directory ' /home/user/iftop-0.17/config' 
make[2]: Nothing to be done for ' all' .
make[2]: Leaving directory ' /home/user/iftop-0.17/config' 
.
.
make[2]: Leaving directory ' /home/user/iftop-0.17' 
make[1]: Leaving directory ' /home/user/iftop-0.17' 

linuxhelp iftop-0.17 # make install
Making install in config
make[1]: Entering directory ' /home/user/iftop-0.17/config' 
make[2]: Entering directory ' /home/user/iftop-0.17/config' 
make[2]: Nothing to be done for ' install-exec-am' .
make[2]: Nothing to be done for ' install-data-am' .
make[2]: Leaving directory ' /home/user/iftop-0.17/config' 
make[1]: Leaving directory ' /home/user/iftop-0.17/config' 
make[1]: Entering directory ' /home/user/iftop-0.17' 
make[2]: Entering directory ' /home/user/iftop-0.17' 
/bin/bash ./config/mkinstalldirs /usr/local/sbin
  /usr/bin/install -c iftop /usr/local/sbin/iftop
/bin/bash ./config/mkinstalldirs /usr/local/man/man8
mkdir -p -- /usr/local/man/man8
 /usr/bin/install -c -m 644 ./iftop.8 /usr/local/man/man8/iftop.8
make[2]: Leaving directory ' /home/user/iftop-0.17' 
make[1]: Leaving directory ' /home/user/iftop-0.17' 

Now that iftop has been installed, go to your console and run the iftop command without any arguments to view bandwidth usage of default interface,

linuxhelp iftop-0.17 # iftop
interface: ens33
IP address is: 192.168.7.234
MAC address is: 00:0c:29:f8:f9:81

You can use iftop to monitor linux network Interface. For that, run the following ifconfig command or ip command to find all attached network interfaces on your Linux system.

linuxhelp iftop-0.17 # ip addr show 
1: lo: < LOOPBACK,UP,LOWER_UP>  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: < BROADCAST,MULTICAST,UP,LOWER_UP>  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:f8:f9:81 brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.234/24 brd 192.168.7.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::19ae:fc6a:5310:718b/64 scope link 
       valid_lft forever preferred_lft forever

Then use the -i flag to specify the interface you want to monitor

linuxhelp iftop-0.17 # iftop -i ens33
interface: ens33
IP address is: 192.168.7.234
MAC address is: 00:0c:29:f8:f9:81


With this, the tutorial on installation and usage of iftop comes to an end.

FAQ
Q
How to Specify a listening interface in iftop?
A
If your system has more than 1 interfaces to monitor, we can specify particular interface. Let say if we want to monitor eth0 interface, we can use -i option followed by the interface name.

# iftop -i eth0
Q
How to specify the network for traffic analysis using iftop?
A
We can also ask iftop to only monitor specified network mask. To use this, we can use -F option followed by network mask.



# iftop -F 255.255.0.0
Q
What is the iftop?
A
iftop is defined as an application that listens to network traffic on a named interface and displays a table of current bandwidth usage by pairs of hosts. Iftop works like top command do the same thing for CPU.
Q
How to extract the iftop?
A
To extract the iftop by this command
$ tar zxvf iftop-0.17.tar.gz
Q
How to turn on the port number for iftop?
A
To turn on port display, add -P option with iftop

# iftop -P