Flexible NetFlow

  • networking
  • SNMP
  • NetFlow
  • Monitoring

Network Administrators and Engineers need to obtain statistics for their network infrastructure, while SNMP does a great job at this it by providing us broad information such as packet count, interface changes, and device health, it cannot provide us granular information about our networks. This is why Cisco introduced NetFlow, a tool that works alongside SNMP by letting us obtain information and statistics for the unique types and characteristics of data flowing through interfaces. In this post I will discuss how to fundamentally implement NetFlow and concepts revolving around it.

Original NetFlow

Once NetFlow is enabled on an interface it will begin the following:

  • Sort all packets into existing or new “flows” based on:
    • Source IP
    • Destination IP
    • Source & Destination Port Numbers
    • IP Protocol / TCP / UDP (L3 Protocol Type)
    • ToS Byte
    • Input Interface
  • Collect flow data and place it into a NetFlow Cache where it will be temporarily stored unless configured to have persistent storage.
    • This information can be viewed with IOS CLI commands, or by exporting it to a NetFlow Collector.
  • How NetFlow cache entries expire or triggers occur:
    • Flow has been idle for a specified period of time (15-seconds default)
    • Flow is classified as “long-lived” (30-minutes) this flow is exported and if traffic from this flow is ongoing a new Flow Cache entry is built.
    • TCP connections in which FIN or RST flags are seen.
    • In the event the cache becomes full, heuristics are applied to aggressively age groups of flows out.
  • Expired flows are grouped together into NetFlow Export datagrams and are sent to NetFlow Collector typically (but not always) UDP port 2055.

Flexible NetFlow

Before we’re able to begin

R1(config)# ip cef
R1(config)# flow monitor MON_NAME

Custom Records

R1(config)# flow record REC_NAME
R1(config-flow-record)# decription WEB_SERVER
R1(config-flow-record)# match ipv4 

Setting up a NetFlow Collector in Linux

The following should work on:

  • Alma Linux
  • RHEL
  • Rocky Linux
  • CentOS
  • Fedora
  • Untested but shouldn’t have issues on Ubuntu either.

Before we can begin we must configure the Cisco network device’s EXPORTER:

R1(config)# flow exporter EXP_DATA_TO_PC
R1(config-flow-exporter)# description ### TRAFFIC_TO_LAN ###
(config-flow-exporter)# destination 10.0.0.1
(config-flow-exporter)# transport udp 2055
  • We’ll configure the following:
    • Descriptive name to identify what the EXPORTER is for
    • Destination address of our NetFlow Collector
    • Destination UDP port our NetFlow Collector is listening on

Once this is accomplished we can move onto configuring our Linux server to be a NetFlow Collector. We have a couple different options as to how we’d like to collect and format our Flows. I’ve detailed a few below along with their advantages and disadvantages:

Enterprise Solutions

Tool / Solution Advantages Disadvantages / Trade-offs
ElastiFlow (on top of e.g. ELK/Elastic Stack) • Highly scalable — built to integrate with Elastic Stack, which means full-text search, indexing, long-term storage, dashboards, alerting, and analysis across large flow datasets. SourceForge+1
• Good for multi-source flow collection, long retention, and correlation with other telemetry/log data.
• Great for visibility, compliance, security, capacity planning, trend analysis.
• More complex to deploy and maintain (need to run and manage Elastic Stack, storage, indexing).
• Requires decent hardware or cluster resources to handle large flow volume efficiently.
• Overkill for small or moderately sized networks complexity may outweigh benefit.
Commercial / Proprietary Suite (e.g. SolarWinds NetFlow Traffic Analyzer and similar paid tools) • Turn-key, polished dashboards, reporting, alerting, user-friendly interfaces, vendor support, and often integration with other enterprise monitoring tools. GoReplay+1
• Designed to handle high flow volumes and many exporters/reports; good for compliance, auditing, bandwidth planning, traffic engineering.
• Less “glue work” — less need for manual scripting, custom integration, or homegrown retention.
• Cost licensing or subscription.
• Vendor lock-in; less flexibility compared to open-source tools.
• For smaller networks or labs, likely overkill and not cost-efficient.

SoHo / Home-Lab / SMB Solutions

Tool / Solution Advantages Disadvantages / Trade-offs
nfdump / nfcapd (and optionally nfsen) • Collects NetFlow / IPFIX / sFlow data reliably. GitHub+2Bits ‘n Bytes+2
• Highly efficient and flexible supports IPv4/IPv6, multiple NetFlow versions (v5/v7/v9, IPFIX), and can handle compressed or binary data. Medium+1
• Good for on-disk archival: you get flow dump files that you can keep, compress, archive.
• CLI-based: easy to script (cron jobs, log rotation, archiving).
• Basic UI or none analysis is generally via command line or third-party front-ends unless you add a GUI/frontend.
• For large traffic volumes / high flow rates, performance and usability may be limited compared to modern tools.
• Less “polish”: no built-in dashboards, alerting, long-term indexing, or advanced analytics need to build around it manually.
pmacct • Very flexible: can collect NetFlow, IPFIX, sFlow and aggregate, filter, and export data in many formats (files, SQL, time-series DBs, etc.). elastiflow.com+1
• Good for traffic accounting, usage reporting, integration with databases or monitoring stacks (e.g. GNOC-style traffic logging).
• Lightweight enough for modest lab or small production networks.
• You need to build much of the surrounding infrastructure (storage, dashboards, maybe custom export scripts) more work than “plug-and-play.”
• May not scale as well for very high flow volumes without careful tuning or external DB backends.
• Less real-time “polished UI” out of the box compared to modern enterprise tools.
ntopng (usually with nProbe as collector/probe) • Web-based interface, with nice dashboards, top-talkers, flow summaries, host-level views, protocol breakdowns much easier to digest than raw flow dumps. Wikipedia+2Network Admin Tools+2
• Supports NetFlow / IPFIX / sFlow (via nProbe) and combines multiple flow sources into one view useful if you have several routers/switches exporting flows. ntop+1
• For a home lab or small office, gives a very “graphical console” feel without heavy ops.
• Requires more resources than simple CLI tools (especially when using nProbe + ntopng together).
• For very high flow rates (big enterprise networks), may require careful tuning or more powerful hardware.
• Open-source/community version may lack some advanced enterprise features (alerting, long-term storage, multi-tenant, etc.).
In this demonstration I’ve chosen to use a combination of IPFIX, nfdump, and nfsen.
#!/usr/bin/env bash

FLOW_DIR="/var/log/ipfix"
ARCHIVE_DIR="/var/log/ipfix/archive"
DAYS_OLD=7
LOG_FILE="/var/log/ipfix/archive/ipfix_archive.log"
FILE_PATTERN="flows.*"

export PATH=/usr/sbin:/usr/bin:/sbin:/bin

/usr/bin/mkdir -p "$ARCHIVE_DIR"

/usr/bin/touch "$LOG_FILE"

# Log stdout & stderr
exec >>"$LOG_FILE" 2>&1

echo "[$(/usr/bin/date '+%Y-%m-%d %H:%M:%S')] Starting NetFlow Archive..."

# Find old Netflow logs
/usr/bin/find "$FLOW_DIR" -maxdepth 1 -type f \
	-name "$FILE_PATTERN" ! -name '*.gz' \
	-mtime +"$DAYS_OLD" -print0 | \


while IFS= read -r -d '' file; do
	echo "Archiving: $file"
	# Compress
	/usr/bin/gzip -9 "$file"
	# Move compressed files to archive dir
	/usr/bin/mv "${file}.gz" "$ARCHIVE_DIR"/
done

/usr/bin/mv "$FLOW_DIR"/*.gz "$ARCHIVE_DIR"/


echo "[$(/usr/bin/date '+%Y-%m-%d %H:%M:%S')] Starting NetFlow Archive..."

Back to all write-ups