· 7 min read

Flexible NetFlow on Cisco IOS-XE for DDoS Detection

To configure Flexible NetFlow on Cisco IOS-XE for DDoS detection, you build four objects: a flow record, a flow exporter, a flow monitor and an optional sampler. Then you attach the monitor to your edge interfaces and send NetFlow v9 or IPFIX to a collector. This guide gives a working config, the commands to verify it, and the mistakes that most often leave a collector blind or confused.

All addresses below come from documentation ranges: the router loopback is 192.0.2.1, the collector is 192.0.2.10, and customer space is 198.51.100.0/24 and 203.0.113.0/24.

What the collector needs from the router

A DDoS detector works on per-destination bps and pps, so the flow record must carry enough to attribute traffic to a victim IP and classify the attack:

Anything beyond that is optional. Keep the record small: every extra field increases cache size and export volume.

Step 1: Flow record

flow record DDOS-RECORD
 description Fields for DDoS detection
 match ipv4 source address
 match ipv4 destination address
 match ipv4 protocol
 match transport source-port
 match transport destination-port
 match interface input
 collect interface output
 collect transport tcp flags
 collect counter bytes long
 collect counter packets long
 collect timestamp sys-uptime first
 collect timestamp sys-uptime last
 collect routing next-hop address ipv4

The match fields form the flow key. The collect fields are just attached data. Including match interface input means the same 5-tuple seen on two interfaces creates two flows, which is what you want at an edge.

Some platforms reject certain fields or cap the number of key fields, especially Catalyst switches with hardware flow tables. Check your platform's Flexible NetFlow documentation before copying a record verbatim.

Step 2: Flow exporter

flow exporter NIXMON-EXP
 description DDoS detection collector
 destination 192.0.2.10
 source Loopback0
 transport udp 2055
 export-protocol netflow-v9
 template data timeout 60
 option interface-table timeout 300

Notes:

Step 3: Flow monitor

flow monitor NIXMON-MON
 description DDoS detection monitor
 exporter NIXMON-EXP
 cache timeout active 60
 cache timeout inactive 15
 record DDOS-RECORD

The active timeout controls how often long-lived flows are exported. For DDoS detection, shorter is better: a 30 minute default means a volumetric flood is reported late. 60 seconds is a reasonable start; go lower if the router CPU and collector handle it. Inactive 15 seconds flushes finished flows promptly.

Step 4: Sampler (optional but common)

On busy edge routers, unsampled flow export can be heavy on cache and CPU. A sampler reduces load:

sampler SMP-1-IN-1000
 description Random 1 in 1000
 mode random 1 out-of 1000

Pick a rate based on traffic level and the smallest attack you want to catch. Sampling makes small floods noisy and delays detection, while a very low rate (or none) increases router load. The collector must know the sampling rate so it can scale counters back up. Many collectors read it from the exported options template; if yours doesn't, configure it manually. We cover the tradeoffs in more depth in our article on NetFlow DDoS detection thresholds, baselines and sampling.

Step 5: Attach to interfaces

Apply the monitor on the interfaces facing transit, peering and IXes:

interface TenGigabitEthernet0/0/0
 description Transit AS64500
 ip flow monitor NIXMON-MON sampler SMP-1-IN-1000 input
!
interface TenGigabitEthernet0/0/1
 description IX peering
 ip flow monitor NIXMON-MON sampler SMP-1-IN-1000 input

Without sampling, drop the sampler keyword:

 ip flow monitor NIXMON-MON input

For IPv6, create a separate record with match ipv6 ... fields and a separate monitor, then attach it with ipv6 flow monitor. An IPv4 record does not cover IPv6 traffic.

Step 6: Verify

Start on the router.

show flow exporter NIXMON-EXP
show flow exporter NIXMON-EXP statistics
show flow exporter NIXMON-EXP templates
show flow monitor NIXMON-MON
show flow monitor NIXMON-MON cache
show flow monitor NIXMON-MON statistics
show flow interface TenGigabitEthernet0/0/0
show sampler SMP-1-IN-1000

What to look for:

Then check the collector side. On a Linux collector:

sudo tcpdump -ni eth0 udp port 2055 and host 192.0.2.1

If packets arrive here but the collector shows nothing, the issue is likely template handling or the host firewall. If nothing arrives, check routing, ACLs, control-plane policing and the exporter source.

Common pitfalls

Template timeouts

NetFlow v9 and IPFIX are template-based: data records are meaningless until the collector has received the template. If the collector restarts or you add a new exporter, it drops data until the next template refresh. With a 600 second timeout, that is up to 10 minutes of invisible traffic, possibly during an attack. Set template data timeout 60 (or lower), and confirm the collector copes with the refresh rate. Also check that options templates (sampling, interface table) are exported, as they are separate.

Asymmetric ingress/egress monitoring

Flexible NetFlow attached with input only sees packets entering that interface. In an ISP, traffic often enters through transit A and leaves through transit B. If you monitor only some interfaces, you may see only half of a conversation, or miss an attack arriving over an unmonitored link.

Practical rules:

Sampling rate mismatch

If the router samples 1:1000 but the collector assumes 1:1, a 10 Gbps attack looks like 10 Mbps and nothing triggers. Always confirm the scaled counters against interface counters (show interface rate) once.

Export packet loss and MTU

Large template or data packets can fragment when sent over tunnels. Keep the exporter path clean, and if needed set transport udp with mtu 1400 in the exporter. Also look at CoPP or ACLs that might drop UDP 2055 on the collector's host.

Timeouts that are too long, caches that are too small

A long active timeout delays detection. A cache that is too small during an attack, with many random source IPs, drops or ages out flows early. Watch show flow monitor ... statistics for cache overflow and consider increasing cache entries.

Wrong source interface or VRF

If the exporter's source loopback is not reachable from the collector, or the destination lives in a VRF you didn't specify, exports silently fail. show flow exporter ... statistics shows it.

From flows to action

Once flows arrive, the collector compares per-IP and per-prefix bps/pps against thresholds and triggers mitigation. NixMon accepts NetFlow v5/v9, IPFIX and sFlow and can announce BGP blackhole (RTBH) or FlowSpec routes based on those detections. For networks with their own ASN and at least one /24, NixGuard Edge can move traffic through cloud scrubbing and return clean traffic over a GRE tunnel with BGP. You can see how the pieces fit on the NixMon monitoring page, or point your Cisco exporter at the collector with the 15-day free trial, no credit card required.

Quick checklist

  1. Flow record with 5-tuple, TCP flags, counters, interfaces, timestamps
  2. Exporter with loopback source, correct VRF, template timeout of 60 seconds
  3. Monitor with active timeout 60 and inactive timeout 15
  4. Sampler matched to traffic level, rate known by the collector
  5. Monitor attached on input of all external interfaces
  6. Router and collector verified with show flow commands and tcpdump
  7. Counters compared with SNMP interface rates

Frequently asked questions

Should I use NetFlow v9 or IPFIX on Cisco IOS-XE?

Both work with Flexible NetFlow. Use whichever your collector supports; IPFIX is the standardized version of v9, but for DDoS detection the exported fields matter more than the protocol version.

Do I need sampling for DDoS detection on IOS-XE?

Not always. Sampling reduces CPU and cache load on busy edge routers, but lowers accuracy for small attacks. Choose a rate based on traffic volume, and make sure the collector scales counters by the sampling rate.

Why does the collector show no data even though the router exports?

The most common causes are missing templates (timeout too long or collector restarted), a wrong source interface or VRF, firewall rules on UDP 2055, or a sampling or direction mismatch. Check show flow exporter statistics and run tcpdump on the collector.

Should I monitor ingress, egress or both?

For attack detection, monitor ingress on all external interfaces. Adding egress on the same path can double-count traffic unless the collector uses interface direction to separate it.

Point your Cisco exporter at NixMon with a free 15-day trial.Learn more