Network & Connectivity

Traffic and Bandwidth Monitoring

How to check bandwidth consumption and network traffic on your server with vnstat, iftop and nethogs

vnstat: Historical Bandwidth Consumption

vnstat records traffic over time and allows you to see how many GB you've consumed per day, week, or month. Perfect for keeping track of monthly traffic included in your plan.

Installation

apt install vnstat -y         # Debian/Ubuntu
dnf install vnstat -y         # CentOS/AlmaLinux

systemctl enable --now vnstat

Usage

# General summary
vnstat

# Hourly traffic (last 24 hours)
vnstat -h

# Daily traffic
vnstat -d

# Weekly traffic
vnstat -w

# Monthly traffic
vnstat -m

# Continuous update every 5 seconds
vnstat -l

# Specify the interface (e.g., eth0, ens3)
vnstat -i eth0 -m

Find Your Network Interface Name

ip link show
# or
vnstat --iflist

iftop: Real-time Traffic per Connection

iftop shows active connections and their bandwidth consumption in real-time. Useful for quickly understanding who's using lots of bandwidth.

apt install iftop -y

# Start (requires root)
iftop

# On specific interface
iftop -i eth0

# Show ports
iftop -P

Useful keys inside iftop:

  • n: show/hide DNS resolution
  • p: show/hide ports
  • s: sort by source
  • d: sort by destination
  • q: exit

nethogs: Traffic per Process

nethogs associates network traffic with individual processes or applications. Ideal for understanding which program is consuming bandwidth.

apt install nethogs -y

nethogs
nethogs eth0    # On specific interface

Example output:

NetHogs version 0.8.7

PID    USER    PROGRAM        DEV    SENT    RECEIVED
1234   www-data nginx          eth0   1.2 MB  0.3 MB
5678   root    sshd           eth0   0.1 MB  0.0 MB

nload: Real-time Speed per Interface

nload shows current upload and download speed with a graphical bar:

apt install nload -y
nload

Quick Check Without Additional Tools

If you don't want to install anything:

# Traffic on interface every second (RX = received, TX = sent)
watch -n 1 cat /proc/net/dev

# Active connections and count per IP
ss -tn | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head -20

# How many connections per state (ESTABLISHED, TIME_WAIT, etc.)
ss -tan | awk '{print $1}' | sort | uniq -c | sort -rn

Check Total Bandwidth Consumption

If your plan has a monthly traffic limit, you can monitor it with vnstat:

# Current month's traffic
vnstat -m | grep "$(date +%Y-%m)"

The VirtFusion panel also shows traffic graphs over time in the Graphs section. See: Statistics and Graphs

On this page