Monitoring network bandwidth is an essential task for any Linux system administrator. While tools like top show CPU and RAM usage, they don’t tell you how much data your server is pushing over the network. For a lightweight, persistent way to track bandwidth usage over time, vnStat is one of the best command-line utilities available for Ubuntu.
What is vnStat?
Unlike other network monitoring tools that actively sniff traffic and consume CPU resources, vnStat simply reads network statistics provided by the Linux kernel. This makes it incredibly lightweight and perfect for running in the background on low-resource servers.
How to Install and Use vnStat
- Open your terminal or connect to your server via SSH.
- Update your package list and install vnStat by running:
sudo apt update && sudo apt install vnstat - Once installed, the vnStat service will start automatically in the background and begin collecting data.
- To view your network statistics, simply type:
vnstat
Advanced vnStat Commands
By default, vnStat provides a quick summary. You can use flags to view more specific data:
- Live traffic: Use
vnstat -lto see a live, real-time view of your bandwidth usage. - Hourly breakdown: Use
vnstat -hto see traffic statistics for the past 24 hours. - Daily breakdown: Use
vnstat -dfor day-by-day statistics.
Because vnStat stores its data in a database, your network history will survive system reboots, making it an invaluable tool for tracking monthly server bandwidth quotas.