How to monitor network connections on Linux

How to monitor network connections on Linux

How to monitor network connections on Linux with iftop

iftop is a very useful command that can help us troubleshoot network issues and show statistics about download speed and network connections

to install it on ubuntusudo apt-get -y install iftop

Get a list of network connections and info for download / uploadsudo iftop -n -P -t -s1 -L1000
interface: wlp108s0
IP address is: 192.168.1.168
IPv6 address is: 2a02:587:e3e:d700:cc8a:4e6f:447d:4f4a
MAC address is: 34:e1:2d:55:ea:ec
Listening on wlp108s0
  # Host name (port/service if enabled)            last 2s   last 10s   last 40s cumulative
--------------------------------------------------------------------------------------------
  1 [2a02:587:e3e:d700:cc8a:4e6f:447d::45536 =>     76,4Kb     76,4Kb     76,4Kb     19,1KB
    [2606:4700:30::681b:bb88]:http           <=     4,31Mb     4,31Mb     4,31Mb     1,08MB
--------------------------------------------------------------------------------------------
Total send rate:                                     76,4Kb     76,4Kb     76,4Kb
Total receive rate:                                  4,31Mb     4,31Mb     4,31Mb
Total send and receive rate:                         4,39Mb     4,39Mb     4,39Mb
--------------------------------------------------------------------------------------------
Peak rate (sent/received/total):                     76,4Kb     4,31Mb     4,39Mb
Cumulative (sent/received/total):                    19,1KB     1,08MB     1,10MB
============================================================================================

Input parameter explaination:-n: do no resolve ip addresses-P: display ports-t: plain text output-s<n> n the number of seconds to sample traffic-L<n> n the max number of lines to display

Output explaination per entry:1st line of hostname/port: an ip/port from our server'=>' The speed we upload for the last 2s, 10s, 40s and cumulative2nd line of hostname/port: an ip/port from the remote server'<=' The speed we download for the last 2s,10s,40s and cumulative

As you nottice appart from each connection entry we can get cumulative statistics about totals send — recieve rate, peak rate and cumulative sent/receive for the sampling period--------------------------------------------------------------------------------------------
Total send rate:                                     76,4Kb     76,4Kb     76,4Kb
Total receive rate:                                  4,31Mb     4,31Mb     4,31Mb
Total send and receive rate:                         4,39Mb     4,39Mb     4,39Mb
--------------------------------------------------------------------------------------------
Peak rate (sent/received/total):                     76,4Kb     4,31Mb     4,39Mb
Cumulative (sent/received/total):                    19,1KB     1,08MB     1,10MB
============================================================================================

This tool is usable when you want to troubleshoot something on the fly, what about historical data? how we can use this tool to log them? see this article

iftop: how to log network connections for troubleshooting
In the previous article i did a short review of the iftop command, this article will show how to use this command to…
Join Medium with my referral link - Konstantinos Patronas
Read every story from Konstantinos Patronas (and thousands of other writers on Medium). Your membership fee directly…