Real-Time Network Bandwidth Monitoring on Ubuntu with iftop

Overview

Diagnosing sudden throughput spikes and isolating network bottlenecks demands responsive, socket-level visibility. This hands-on walkthrough covers deploying and mastering iftop on Ubuntu—from package installation and live session profiling to non-interactive CLI reports and packet filtering.

Installing iftop and Inspecting Network Interfaces

Before monitoring traffic, query the operational state and names of your network adapters by running ip -br link.

Verifying network interface status with ip -br link

Refresh repository metadata and pull the utility directly from the official package archive using sudo apt-get update -qq && sudo apt-get install -y iftop.

Installing iftop on Ubuntu

The iftop command listens on a designated interface, drawing a dynamically updated top-like summary of bandwidth consumption sorted by remote and local host pairs.
Inspecting the built-in reference documentation reveals critical operational flags:
⚙️ [Essential Command-Line Switches]

-h : Prints the command reference and option overview.
-i <interface> : Binds packet sniffing to a selected adapter (such as eth0, ens33, etc.).
-n : Disables DNS lookups to display raw numeric IP addresses.
-N : Suppresses port-to-service mapping, preserving original port numbers.
-p : Puts the adapter into promiscuous mode to capture ambient segment traffic.
-b : Strips the graphical visual bar chart from the output view.
-B : Switches measurement units from bits to bytes.
-f <filter code> : Applies custom pcap-style filter expressions to isolate specific packet flows.

Reviewing command options with iftop -h

Standard Bandwidth Inspection and Text Output Mode

To collect a quick snapshot without entering the interactive ncurses UI, stream a short terminal report using sudo iftop -t -s 2 -n.
Here, -t switches to plain text stdout mode, -s 2 caps data sampling at a two-second window before cleanly exiting, and -n bypasses reverse DNS resolution to speed up data delivery.

Running iftop in text snapshot mode

When you need granular visibility into specific connection ports, append the port display flag with sudo iftop -t -s 3 -P.
Passing -P reveals active transport-layer port numbers (or assigned protocol names) beside each IP endpoint. Depending on system load and incoming frame volume during the 3-second sample interval, output generation may encounter brief processing timeouts.

Capturing port-level connection metrics

Targeting Interfaces and Suppressing Name Resolution

Identify your primary outbound adapter by querying the kernel routing table and storing the interface name into an environment variable with DEFAULT_IFACE=$(ip route | grep default | awk '{print $5}' | head -n 1).

Extracting the default gateway interface

Verify that the target adapter name was captured cleanly by running echo "Target interface: $DEFAULT_IFACE".

Confirming captured target interface

Launch an isolated, non-resolving bandwidth dump on that dynamic device using sudo iftop -i "$DEFAULT_IFACE" -t -s 2 -N -n.
The -i argument locks analysis strictly onto the default route adapter, while combining -n with -N prevents network lookup latency, reporting raw IP-and-port sockets immediately.

Inspecting traffic on target interface without hostname lookups

Simulating Network Load and Measuring in Bytes

To see bandwidth spikes reflected in your metrics, initiate a background download stream of test payload data via curl -s -o /dev/null http://speedtest.tele2.net/1MB.zip &.

Generating simulated outbound network traffic

Evaluate this transfer in storage-centric byte units rather than network bits over a 3-second window using sudo iftop -t -s 3 -B.
The -B switch formats throughput figures into standard byte increments (B, KB, MB), while -t and -s 3 deliver an un-rendered static terminal summary upon expiration.

Measuring network bandwidth in bytes

Synchronize your terminal and ensure the background download thread has concluded by invoking wait.

Waiting for background transfer completion

With these fundamental techniques, you can rapidly pinpoint bandwidth hogs and troubleshoot network saturation directly from the Ubuntu command line.