Linux Display Bandwidth Usage on Network Interface By Host Using iftop command

The iftop command listens to network traffic on a named network interface, or on the first interface, it can find which looks like an external interface if none is specified, and displays a table of current bandwidth usage by pairs of hosts. The iftop is a perfect tool for remote Linux server over an ssh based session.

iftop must be run by the root or the user who has sufficient permissions to monitor all network traffic on the network interface. See how to install iftop on CentOS/RHEL based server.

ADVERTISEMENTS

Installation

Type the command as per your Linux distro:

Install iftop on a Debian/Ubuntu Linux

Type the following apt-get command/apt command:
$ sudo apt-get install iftop

Install iftop on a CentOS/Fedora/RHEL/Scientific/Oracle Linux

Type the following yum command (first turn on EPEL repo):
$ sudo yum install iftop
Fedora Linux user type the following dnf command:
$ sudo dnf install iftop

Install iftop on Arch Linux

Type the following pacman command:
$ sudo pacman -S iftop

Install iftop on Alpine Linux

Type the following apk command:
# apk add iftop

Install iftop on Suse/OpenSuse Linux

Type the following zypper command:
# zypper install iftop

A note about installing iftop on Unix-like system

You can install iftop on Unix-like system such as FreeBSD, OpenBSD, MacOS and others too. This page only deals with Linux operating system. For example on FreeBSD one can install iftop using the following pkg command:
# pkg install iftop
On macOS Unix one can install it using the brew command:
$ brew install iftop

Examples

The syntax is:
iftop
iftop -i interface
iftop [options]

Type iftop command at the shell prompt to display traffic:
# iftop
Sample outputs:

Linux Display Bandwidth Usage on Network Interface using iftop command

iftop in action (click to enlarge image)

In this example, I am using eth0 interface:
# iftop -i eth0
Sample outputs:
Animated gif 01: iftop command in action

Animated gif 01: iftop command in action

However, iftop works best when you use filters. For example, if you want to find out how much bandwidth users are wasting or trying to figure out why the network is slow, run:
# iftop -f icmp
You can display or analyses packet flowing in and out of the 192.168.1.0/24 network:
# iftop -F 192.168.1.0/24
Disable output for DNS traffic by using filter code such as:
# iftop -f 'not port domain'
iftop has many options read man page for further information see its man page – iftop(8)
See also:

Conclusion

And there you have it, you just learned how to display bandwidth usage on an interface by host. To get more info type the following man command or visit this page:
$ man iftop
$ iftop -h

iftop command options

OptionDescription
-h display this message
-n don’t do hostname lookups
-N don’t convert port numbers to services
-p run in promiscuous mode (show traffic between other hosts on the same network segment)
-b don’t display a bar graph of traffic
-B Display bandwidth in bytes
-i interfacelisten on named interface
-f filter codeuse filter code to select packets to count (default: none, but only IP packets are counted)
-F net/maskshow traffic flows in/out of IPv4 network
-G net6/mask6show traffic flows in/out of IPv6 network
-ldisplay and count link-local IPv6 traffic (default: off)
-Pshow ports as well as hosts
-m limitsets the upper limit for the bandwidth scale
-c config filespecifies an alternative configuration file
-tuse text interface without ncurses
-o 2sSort by first column (2s traffic average)
-o 10sSort by second column (10s traffic average) [default]
-o 40sSort by third column (40s traffic average)
-o sourceSort by source address
-o destinationSort by destination address
-s numprint one single text output afer num seconds, then quit
-L numnumber of lines to print
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdig host ip nmap
Package Managerapk apt
Processes Managementbg chroot disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w

ADVERTISEMENTS
8 comments… add one
  • Anonymous Sep 7, 2006 @ 13:11

    It is a very useful program. This commando shows I deal and the port of a single IP

    iftop -P -i any -F 62.165.165.245/32

  • Artem Nosulchik Oct 19, 2007 @ 11:32

    It’s also possible to apply filter when iftop is already running: just press “f” button and type filter you wish like:
    Net filter> host 192.168.0.7

  • ahmbay Aug 29, 2009 @ 9:36

    this is very usefull program. Thanks..

  • alfin Sep 10, 2009 @ 20:33

    thanks, its great
    but i still have one question, can iftop change source ip (ex: 192.168.1.2 at picture above) to hostname from each pc that connected?

    regrads,..

  • Penton Oct 14, 2009 @ 4:50

    marvellous! This application is so useful. I didn’t expect it be to user friendly. 🙂

  • blogger Feb 13, 2012 @ 1:44

    thanks, it works great with my wireless nic.

  • Pluto Apr 17, 2014 @ 4:49

    Something that works well via command line (especially for SSH) is iptraf. That lets you view stats with a wide variety of detail. Probably doesn’t work as well as this, but it works well enough 😉

  • Ismail May 7, 2017 @ 14:30

    Thanks iftop is really useful tool, but how you to make the opposite of this “iftop -F 192.168.1.0/24” i mean to exclude local bandwidth?

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.