Hold Tight...

0 %
Driving cybersecurity excellence
Innovator behind Kodachi OS
  • Residence:
    ::0
  • Uptime Binary:
    110001
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Cybersecurity
Programming & R&D
Cryptocurrency
AI & vibe coding
  • Bash
  • Gambas
  • Delphi
  • PHP
  • Visual Basic
  • Rust

Effortlessly Set Up ntopng: Monitor Your Network in Minutes

03/11/2024
3 min readDeep Tech4 code examplesUpdated October 2026

Key points

  • A Bash script that adds the ntop repository, installs ntopng with its companion packages, detects your network interface and starts the service.
  • It was written for Debian 12: on Debian 13 replace its wget line with the two lines in the update.
  • nprobe, n2disk and cento are commercial ntop products and run in a limited mode without a licence.

Automate ntopng Installation with This Bash Script

Updated October 2026: I wrote this ntopng setup script for Debian 12, and it downloads the bookworm repository package by name. On Debian 13 (trixie, released in August 2025), replace its wget line with the two lines below, which pick the repository for your release. ntop publishes packages for Debian bookworm and trixie and for Ubuntu 22.04, 24.04 and 26.04; on Ubuntu the folder is the version number, for example apt/24.04/.

  • The script adds contrib to /etc/apt/sources.list. A system that uses the deb822 format (/etc/apt/sources.list.d/debian.sources) needs contrib added to the Components: line of that file instead.
  • nprobe, n2disk and cento are commercial ntop products and run in a limited demo mode without a licence; to monitor traffic you only need the ntopng package.
  • Port 4400 is not a security measure. Until the admin/admin password is changed, anyone who reaches that port can log in, so allow it only from your own address in the firewall or reach it through an SSH tunnel.
. /etc/os-release   # on Debian, VERSION_CODENAME is bookworm or trixie
wget "https://packages.ntop.org/apt/${VERSION_CODENAME}/all/apt-ntop.deb"

Setting up ntopng, a high-performance network traffic monitoring tool, on a Debian-based system can be intricate. This Bash script simplifies the process, automating installation and configuration to ensure a seamless setup experience.

What Is ntopng?

ntopng is an advanced network traffic analyzer that provides real-time insights into your network’s performance and usage. It monitors bandwidth, detects anomalies, and enhances network security, making it an invaluable tool for administrators.

Key Features of the Script

  • Root Privileges Check: Ensures the script is executed with the necessary permissions.
  • Network Interface Detection: Automatically identifies the primary network interface for monitoring.
  • Repository Configuration: Adds the official ntopng repository and imports the GPG key for package verification.
  • Dependency Installation: Installs ntopng along with pfring-dkms, nprobe, n2disk, cento and ntap (nprobe, n2disk and cento are commercial; see the note at the top).
  • Configuration Setup: Configures ntopng with detected network interfaces and custom settings.
  • Service Management: Enables and starts the ntopng service, ensuring it’s active and accessible.
  • Error Handling: Includes robust checks to handle issues during installation.

How It Works

  1. Detects Network Interface:
    • Identifies the primary network interface to monitor.
    • Falls back to common private network ranges if detection fails.
  2. Configures the Repository:
    • Adds the official ntopng repository.
    • Updates the package list and verifies repository keys.
  3. Installs ntopng and Dependencies:
    • Downloads and installs necessary packages, including nprobe and pfring-dkms.
    • Cleans up any previous installations for a fresh start.
  4. Configures ntopng Settings:
    • Sets the network interface and local networks for monitoring.
    • Configures the web interface on port 4400 instead of the default 3000.
  5. Manages the Service:
    • Enables ntopng to start at boot.
    • Restarts the service to apply configurations and ensures it is active.
  6. Provides Access Information: Displays the web interface URL and default credentials for easy login.

Quick Start with the ntopng Setup Script

  1. Save and Make Executable: copy the full script at the end of this post into a file named ntopng-setup.sh, then run:
   chmod +x ntopng-setup.sh
  1. Run the Script:
   sudo ./ntopng-setup.sh
  1. Let It Run:
    • Let the script detect your network settings.
    • Watch as it installs and configures ntopng automatically.
  1. Access ntopng:
    • Open your browser and navigate to http://<your-server-ip>:4400.
    • Log in with the default credentials (admin/admin) and change the password immediately.

Benefits

  • Time-Saving: Automates a complex installation and configuration process.
  • Custom Port: Runs the web interface on port 4400 instead of the default 3000 (a different port is not protection; limit access in the firewall).
  • Reliable: Includes error handling to ensure a smooth installation experience.
  • Customizable: Allows adjustments to the network settings and monitored interfaces.

Conclusion

This Bash script takes the hassle out of setting up ntopng on Debian-based systems. By automating the process, it ensures a quick and reliable installation, letting you focus on monitoring your network. Start gaining real-time insights into your network performance today with this powerful tool! For per-second system metrics beside the traffic view, see my Netdata setup script.

ShellScript
#!/bin/bash
# =========================================
# Ntopng Setup Script
# =========================================
#
# Version: 1.0.1
# Author: Warith AL Maawali
#
# Contact:
# - Discord: https://discord.gg/KEFErEx
# - Twitter: https://x.com/warith2020
# - LinkedIn: https://www.linkedin.com/in/warith1977
# - Website: https://www.digi77.com
#
# Copyright (c) 2024 Warith AL Maawali
#
# Description:
# This script automates the installation and configuration of Ntopng on Debian-based systems.
# It performs the following tasks:
# - Ensures root privileges
# - Detects the primary network interface
# - Updates system packages
# - Configures the Ntopng repository
# - Installs Ntopng and its dependencies
#
# License:
# Dual-licensed under:
# 1. Apache License 2.0 (personal, non-commercial use)
# 2. Commercial license (for corporate/organizational use)
# Contact author for commercial licensing details.
#
# Usage:
# sudo ./ntopng-setup.sh
#
# Requirements:
# - Debian-based Linux distribution
# - Root/sudo privileges
# - Active internet connection
# =========================================

# Global configuration variables with descriptive comments
NTOPNG_PORT="4400"                     # Web interface port (non-standard for security)
NTOPNG_CONF="/etc/ntopng/ntopng.conf"   # Main configuration file location
NTOPNG_START="/etc/ntopng/ntopng.start" # Startup configuration file location

# Main installation and configuration function
function install_ntopng() {
  # Network interface detection with progressive fallbacks
  # First try: Get default route interface
  INTERFACE=$(ip route | grep default | awk '{print $5}' | head -n1)

  # Second try: Find first active non-virtual interface
  if [ -z "$INTERFACE" ]; then
    INTERFACE=$(ip link show | grep -v "lo\|docker\|veth\|br-\|vir" |
      grep "UP" | head -n1 | awk -F: '{print $2}' | tr -d '[:space:]')
  fi

  # Exit if no valid interface found
  if [ -z "$INTERFACE" ]; then
    echo "===================="
    echo "ERROR: No valid network interface detected"
    echo "===================="
    exit 1
  fi

  # Detect and configure local networks
  # Excludes virtual interfaces and uses common private ranges as fallback
  LOCAL_NETWORKS=$(ip route | grep -v "default\|docker\|br-\|vir" |
    awk '{print $1}' | tr '\n' ',' | sed 's/,$//')

  # Fallback to common private network ranges if detection fails
  if [ -z "$LOCAL_NETWORKS" ]; then
    LOCAL_NETWORKS="192.168.0.0/24,10.0.0.0/8,172.16.0.0/12"
  fi

  # Clean existing installation if present
  if dpkg -l | grep -q "apt-ntop"; then
    echo "===================="
    echo "Removing existing Ntopng installation..."
    echo "===================="
    # Remove all related packages
    sudo apt-get purge -y apt-ntop
    sudo apt-get autoremove -y

    # Clean up repository keys
    echo "Removing existing repository keys..."
    sudo apt-key del "$(sudo apt-key list | grep -i ntop -B 1 | head -n 1 | awk '{print $9}')" 2>/dev/null || true
  fi

  # Repository configuration
  echo "===================="
  echo "Configuring package repositories..."
  echo "===================="
  if ! grep -q "contrib" /etc/apt/sources.list; then
    sudo sed -i '/^deb\|^deb-src/ s/$/ contrib/' /etc/apt/sources.list
  fi

  # Download and install repository package
  echo "Installing Ntopng repository..."
  if ! wget https://packages.ntop.org/apt/bookworm/all/apt-ntop.deb ||
    ! mv apt-ntop.deb /tmp/ ||
    ! sudo apt install /tmp/apt-ntop.deb; then
    echo "ERROR: Repository configuration failed"
    exit 1
  fi

  # Install Ntopng and dependencies
  echo "Installing Ntopng packages..."
  sudo apt-get clean all
  sudo apt-get update
  if ! sudo apt-get install -y pfring-dkms nprobe ntopng n2disk cento ntap; then
    echo "ERROR: Package installation failed"
    exit 1
  fi
  # Create the config directory
  echo "Creating Ntopng config directory..."
  sudo mkdir -p $(dirname $NTOPNG_CONF)

  # Configure main settings
  echo "Configuring Ntopng..."
  sudo tee $NTOPNG_CONF >/dev/null <<EOL
-i=$INTERFACE
-w=$NTOPNG_PORT
EOL

  # Configure network settings
  sudo tee $NTOPNG_START >/dev/null <<EOL
--local-networks "$LOCAL_NETWORKS"
--interface 1
EOL

  # Service management and validation
  echo "Enabling and starting services..."
  if ! sudo systemctl enable ntopng; then
    echo "ERROR: Failed to enable ntopng service"
    exit 1
  fi

  if ! sudo systemctl restart ntopng; then
    echo "ERROR: Failed to restart ntopng service"
    exit 1
  fi

  if ! sudo systemctl is-active ntopng >/dev/null 2>&1; then
    echo "ERROR: ntopng service is not active"
    exit 1
  fi

  # Installation completion message
  echo "===================="
  echo "Installation successful!"
  ss -tnlp | grep ":$NTOPNG_PORT"
  echo "Access Ntopng at: http://localhost:$NTOPNG_PORT"
  echo "Default credentials: admin/admin"
  echo "Please change the password after first login"
  echo "===================="

  # Cleanup
  rm -f /tmp/apt-ntop.deb
}

# Check for root privileges
if [ "$EUID" -ne 0 ]; then
  echo "ERROR: This script must be run as root"
  exit 1
fi

# Execute main installation function
install_ntopng
ShellScript
Posted in Deep TechTags: