Skip to content

IP Traffic Flow (NetFlow/IPFIX) in RouterOS: A Complete Guide

IP Traffic Flow (NetFlow/IPFIX) in RouterOS: A Complete Guide

Section titled “IP Traffic Flow (NetFlow/IPFIX) in RouterOS: A Complete Guide”

RouterOS Version: 7.x+ Difficulty: Intermediate Estimated Time: 25 minutes

Traffic Flow is RouterOS’s implementation of NetFlow/IPFIX for exporting network traffic statistics to external collectors. It tracks flows passing through the router and exports detailed metadata including source/destination addresses, ports, protocols, byte/packet counts, and timestamps.

Supported export formats:

  • NetFlow v1 - Basic IP packet information
  • NetFlow v5 - Adds ToS, TCP flags, sequence numbers
  • NetFlow v9 - Template-based, extensible, IPv4/IPv6
  • IPFIX - IETF standard based on NetFlow v9

Common use cases:

  • Network traffic analysis and bandwidth monitoring
  • Security auditing and anomaly detection
  • Billing and usage accounting
  • Capacity planning

Key limitation: Traffic Flow only counts traffic processed by the CPU. Hardware-offloaded bridge traffic and fast-path traffic are not included in flow statistics.

How Traffic Flow Works diagram

Traffic Flow monitors packets at the end of input, forward, and output chains. Only traffic reaching these chains is counted—hardware-switched bridge traffic bypasses the CPU entirely.

NetFlow/IPFIX protocol exchange diagram
MenuPurpose
/ip traffic-flowMain configuration
/ip traffic-flow targetCollector destinations
/ip traffic-flow ipfixIPFIX-specific field selection
PropertyTypeDefaultDescription
enabledyes/nonoEnable/disable traffic flow
interfaceslist/allallInterfaces to monitor
cache-entriesenum4kFlow cache size (1k-256k)
active-flow-timeouttime30mMax time before exporting active flow
inactive-flow-timeouttime15sTime before exporting idle flow
packet-samplingyes/nonoEnable sampling (v7+)
sampling-intervalinteger0Sample N consecutive packets
sampling-spaceinteger0Skip N packets between samples
PropertyTypeDefaultDescription
src-addressIP0.0.0.0Source IP for flow packets
dst-addressIP-Collector IP (required)
portinteger2055Collector UDP port
versionenum9Export format (1, 5, 9, ipfix)
v9-template-refreshinteger20Packets between template resends
v9-template-timeouttime0sTime between template resends

IPFIX Field Selection (/ip traffic-flow ipfix)

Section titled “IPFIX Field Selection (/ip traffic-flow ipfix)”
PropertyDefaultDescription
bytesyesInclude byte counts
packetsyesInclude packet counts
src-addressyesInclude source IP
dst-addressyesInclude destination IP
src-portyesInclude source port
dst-portyesInclude destination port
ip-protocolyesInclude protocol number
tcp-flagsyesInclude TCP flags
nat-eventsnoInclude NAT translations
NetFlow Version Comparison diagram
VersionFeaturesBest For
v1Basic IP info (src/dst, protocol, bytes)Legacy collectors
v5ToS, TCP flags, sequence numbersOlder systems
v9Template-based, IPv4/IPv6, extensibleModern collectors
IPFIXIETF standard, multicast, NAT eventsEnterprise deployments

Recommendation: Use NetFlow v9 or IPFIX for modern deployments. They support IPv6 and provide more detailed flow data.

# Enable traffic flow
/ip traffic-flow set enabled=yes
# Add collector
/ip traffic-flow target add dst-address=192.168.1.100 port=2055 version=9
# Verify
/ip traffic-flow print
/ip traffic-flow target print
Section titled “Example 2: IPFIX with Source Address (Recommended)”

Always set src-address to prevent 0.0.0.0 source issues:

/ip traffic-flow set enabled=yes active-flow-timeout=1m
/ip traffic-flow target add dst-address=192.168.1.100 port=2055 \
version=ipfix src-address=192.168.1.1
# Configure IPFIX fields
/ip traffic-flow ipfix set bytes=yes packets=yes src-address=yes \
dst-address=yes tcp-flags=yes

Reduce CPU load by monitoring only WAN interfaces:

/ip traffic-flow set enabled=yes interfaces=ether1-wan,ether2-wan
/ip traffic-flow target add dst-address=10.0.0.50 port=9995 version=9

Example 4: High-Traffic with Sampling (v7+)

Section titled “Example 4: High-Traffic with Sampling (v7+)”
Example 4: High-Traffic with Sampling diagram

For busy networks, enable sampling to reduce CPU usage:

# Sample 1 packet, skip 1000 (approximately 0.1% sampling)
/ip traffic-flow set enabled=yes packet-sampling=yes \
sampling-interval=1 sampling-space=1000
# Larger cache for more concurrent flows
/ip traffic-flow set cache-entries=64k
/ip traffic-flow target add dst-address=192.168.1.100 port=2055 \
version=9 src-address=192.168.1.1

Send flows to primary and backup collectors:

/ip traffic-flow target add dst-address=192.168.1.100 port=2055 \
version=9 comment="Primary collector"
/ip traffic-flow target add dst-address=192.168.1.101 port=2055 \
version=ipfix comment="Backup collector"

Track NAT translations:

/ip traffic-flow set enabled=yes
/ip traffic-flow target add dst-address=192.168.1.100 port=4739 \
version=ipfix src-address=192.168.1.1
/ip traffic-flow ipfix set nat-events=yes

For collectors that need frequent template refreshes:

/ip traffic-flow target set [find] v9-template-refresh=10 v9-template-timeout=1m

Causes:

  • src-address set to 0.0.0.0 (Linux drops martian packets)
  • Firewall blocking UDP to collector
  • Wrong collector port

Solution:

# Always set src-address
/ip traffic-flow target set [find] src-address=192.168.1.1
# Verify connectivity
/ping 192.168.1.100
# Check firewall allows outbound UDP
/ip firewall filter print where chain=output

Causes:

  • Traffic flow enabled but no traffic reaching CPU
  • Interfaces setting excludes monitored interfaces

Solution:

# Check interfaces setting
/ip traffic-flow print
# Ensure interfaces includes your monitored interfaces
# Verify traffic flow status
/ip traffic-flow print
# Look at sent-flows, sent-packets counters

Problem 3: Hardware-Offloaded Traffic Not Counted

Section titled “Problem 3: Hardware-Offloaded Traffic Not Counted”

Cause: Bridge traffic switched in hardware bypasses CPU.

Solution:

# Disable hardware offload (impacts performance!)
/interface bridge set [find] hw=no

Note: This significantly impacts performance on high-traffic bridges. Consider if you truly need to monitor bridged traffic.

Problem 4: Missing Flows During DDoS/High Load

Section titled “Problem 4: Missing Flows During DDoS/High Load”

Cause: UDP flow packets dropped under load; cache overflow.

Solutions:

# Enable sampling to reduce CPU load
/ip traffic-flow set packet-sampling=yes sampling-interval=1 sampling-space=100
# Increase cache size
/ip traffic-flow set cache-entries=128k

Problem 5: Collector Shows Unknown Fields (v9/IPFIX)

Section titled “Problem 5: Collector Shows Unknown Fields (v9/IPFIX)”

Cause: Collector missed template packet.

Solution:

# More frequent template updates
/ip traffic-flow target set [find] v9-template-refresh=10 v9-template-timeout=30s

Cause: Flow aggregation timing or collector interpretation.

Solution:

# More frequent exports
/ip traffic-flow set active-flow-timeout=1m inactive-flow-timeout=10s
Cache SizeConcurrent FlowsMemory Usage
1k1,024Low
4k4,096Low (default)
16k16,384Medium
64k65,536Medium
256k262,144High

Guideline: Size cache based on expected concurrent flows. A busy router might have thousands of concurrent flows; a small office might have hundreds.

# Check traffic flow status
/ip traffic-flow print
# Look at: enabled, interfaces, sent-flows, sent-packets
# Check target configuration
/ip traffic-flow target print
# Verify: dst-address, port, version, src-address
# Check IPFIX settings
/ip traffic-flow ipfix print
# Monitor flow statistics in real-time
/ip traffic-flow print interval=5
# Watch for incrementing sent-flows count
CollectorTypeNotes
ntopngOpen sourceReal-time visualization (use with netflow2ng collector)
ElastiflowElasticsearch-basedScalable, powerful queries
AkvoradoOpen sourceUser-friendly, modern interface
pmacctOpen sourceFlexible, MySQL/PostgreSQL storage
PRTGCommercialEasy setup, Windows
nfdump/nfsenOpen sourceCLI tools, historical analysis
ScrutinizerCommercialEnterprise features
SolarWinds NTACommercialEnterprise network analysis
  • Torch (/tool torch) - Real-time traffic analysis per interface
  • Graphing (/tool graphing) - Built-in traffic graphs
  • Packet Sniffer (/tool sniffer) - Captures actual packets
  • Accounting (/ip accounting) - IP traffic accounting
  • Connection Tracking (/ip firewall connection) - Active connections
  • CPU-processed traffic only - Hardware-offloaded traffic not counted
  • No BGP AS in v5 - Unlike Cisco, RouterOS doesn’t include AS info in v5
  • UDP transport only - No TCP option; packets may be lost
  • No inline filtering - Cannot filter which flows to export
  • Memory bound - Cache size limits concurrent flow tracking

Traffic Flow exports network statistics to external collectors:

  1. Enable with /ip traffic-flow set enabled=yes
  2. Add target with collector IP, port, and version
  3. Set src-address to avoid 0.0.0.0 source issues
  4. Monitor with /ip traffic-flow print

Key points:

  • Always set src-address on targets
  • Use NetFlow v9 or IPFIX for modern deployments
  • Only CPU-processed traffic is counted
  • Enable sampling for high-traffic environments
  • Template refresh may be needed for v9/IPFIX collectors