NetFlow vs IPFIX vs sFlow: Sampling Rates for DDoS Detection
NetFlow, IPFIX and sFlow all work for DDoS detection, but they differ in how they build data, how quickly they report it, and how much a sampling rate distorts it. For most networks, sampled sFlow or sampled IPFIX at a sensible rate is enough to catch volumetric attacks within seconds. Pick whichever your hardware exports well, then tune the timeouts and sampling rate rather than arguing about the protocol.
This guide explains the real differences, how to choose a sampling rate, and how to verify that your collector sees what you think it sees.
How the three protocols work
NetFlow (v5 and v9)
NetFlow was created by Cisco. The router or switch keeps a flow cache: each unique combination of source IP, destination IP, ports, protocol and a few other keys becomes one entry. When a flow ends or times out, the device exports a record to a collector.
- NetFlow v5 has a fixed record format and supports IPv4 only. No IPv6, no flexible fields.
- NetFlow v9 (RFC 3954) is template-based. The exporter announces which fields it sends, so IPv6, MPLS and extra fields are possible.
- There is no official default port. Collectors commonly use UDP 2055, but any port works.
IPFIX
IPFIX (RFC 7011) is the IETF standard derived from NetFlow v9. It is also template-based and flow-cache-based, but adds variable-length fields, vendor-specific (enterprise) fields and a standardized transport. The IANA-registered port is UDP 4739. If a device says "Flexible NetFlow" or "J-Flow inline" and exports IPFIX, you get the same flow-record model with better field coverage.
sFlow
sFlow works differently. There is no flow cache. The device samples one packet out of every N, copies the first bytes of the packet header (often 128 bytes), and sends it to the collector together with interface counters. The collector builds the flows. sFlow is always sampled by design, runs well in switch ASICs, and the default collector port is UDP 6343.
Side-by-side comparison
| Property | NetFlow v5 | NetFlow v9 / IPFIX | sFlow |
|---|---|---|---|
| Data unit | Flow record | Flow record | Sampled packet header + counters |
| IPv6 | No | Yes | Yes |
| Device state | Flow cache | Flow cache | Stateless sampling |
| Sampling | Optional | Optional | Always |
| Reporting delay | Depends on timeouts | Depends on timeouts | Near real time |
| Payload/header detail | Aggregated fields | Template fields | Raw header bytes |
| Typical use | Legacy gear | Routers, firewalls, hosts | Switches, high-speed ports |
What matters for DDoS detection
Reporting delay
This is the most overlooked setting. Many devices default to an active timeout of 30 minutes (1800 s) on long-lived flows. A UDP flood against one destination can look like a single long flow, and you would hear about it half an hour late. Set the active timeout to 60 seconds or less, and the inactive timeout to 10–15 seconds. sFlow does not have this problem because samples are sent as they happen.
Sampling accuracy
With 1:N sampling, the collector multiplies sampled bytes and packets by N to estimate real traffic. The sFlow specification gives a handy error bound: at 95% confidence, the error is roughly 196 × sqrt(1/c) percent, where c is the number of samples. A thousand samples gives about 6%. A hundred samples gives about 20%.
Large attacks produce many samples quickly, so accuracy gets better exactly when you need it. The weak spot is small or low-rate attacks and rare packet types.
Visibility into attack signatures
For classification you need to see protocol, source port, destination port and TCP flags. All three formats can carry these. sFlow gives raw header bytes, which makes it easy to spot a SYN-only flood or a DNS/NTP/memcached reflection by source port. NetFlow/IPFIX gives the cumulative TCP flags per flow, which is enough for the same decisions.
Choosing a sampling rate
Pick the rate from the link speed and the smallest attack you care about. These are common starting points, not rules:
| Link speed | Starting sampling rate |
|---|---|
| 1 Gbps | 1:512 to 1:1000 |
| 10 Gbps | 1:1000 to 1:2000 |
| 40 Gbps | 1:2000 to 1:5000 |
| 100 Gbps | 1:5000 to 1:10000 |
Then check it with a simple calculation: if your rate is 1:1000 and you want to detect an attack of 50,000 packets per second against a single IP, you receive about 50 samples per second for that destination. That is plenty. If you care about a 2,000 pps SYN flood against a small service, you get 2 samples per second, which may not clear a noisy threshold. Lower the sampling rate (more samples) on edge ports facing small customers, or use a longer detection window.
Rules of thumb:
- Lower N (more samples) costs CPU on the device and bandwidth to the collector. Do not exceed what the control plane can handle.
- Sample at the edge, in one direction. Sampling ingress on every interface is usually enough. Sampling both ingress and egress on the same path double-counts traffic.
- Keep the rate consistent across similar ports so thresholds are comparable.
Hands-on: exporting from a Linux host or router
If you do not have a hardware exporter, a Linux box on a mirror port or in the forwarding path can export flows.
sFlow with hsflowd
# /etc/hsflowd.conf
sflow {
polling = 20
sampling = 1000
collector { ip = 192.0.2.10 udpport = 6343 }
pcap { dev = eth0 }
}
NetFlow v9 with softflowd
softflowd -i eth0 -v 9 -n 192.0.2.10:2055 -t maxlife=60 -t expint=10
The maxlife=60 option is the active-timeout fix described above.
Collector side
# Verify packets arrive
tcpdump -ni eth0 udp port 2055 or udp port 6343 or udp port 4739
# Collect NetFlow/IPFIX with nfdump
nfcapd -w -D -p 2055 -l /var/flows
# Top destinations by packets in the stored data
nfdump -R /var/flows -s dstip/packets -n 10
# Find a possible DNS reflection
nfdump -R /var/flows 'proto udp and src port 53 and bytes > 1000000'
Remember that nfdump shows raw sampled numbers unless the sampling rate is applied. Check that your tool reads the sampling interval from the exporter or that you configure it manually.
A practical detection recipe
- Export from every edge interface where internet traffic enters.
- Set the sampling rate by link speed and keep the active timeout at 60 s or less.
- Aggregate by destination IP in 10–30 second windows. Attacks target a victim, so this is the key you want.
- Alert on packets per second, bits per second, and flow count per destination. Use more than one metric: a SYN flood is visible in pps, a reflection attack in bps.
- Add protocol context: UDP from source port 53/123/11211/389, TCP SYN with no established ratio, fragments, ICMP.
- Link the alert to an action: a mitigation call, a BGP blackhole or FlowSpec rule, or traffic diversion to a scrubbing path.
Common mistakes and fixes
- Rates look 1000x too low. The collector is not applying the sampling rate. Configure it, or make sure the exporter sends the sampling interval in the options template (NetFlow v9/IPFIX) or in the sFlow header.
- Alerts arrive late. Active timeout is still the default. Lower it.
- No IPv6 data. You are using NetFlow v5. Move to v9, IPFIX or sFlow.
- Doubled traffic numbers. Sampling is enabled in both directions on the same flow path, or on both the physical port and a sub-interface.
- Gaps in flow data. UDP export packets are being dropped. Check the collector's receive buffer (
net.core.rmem_max), firewall rules and any rate limits on the exporter's management path. - Wrong timestamps. The exporter's clock is not synchronized. Use NTP everywhere.
- Router CPU spikes. Sampling rate is too aggressive for the platform. Raise N or use hardware or inline flow export.
- Asymmetric traffic hides the attack. If you receive only one direction on a link, collect from all edge routers and correlate at the collector.
So which one should you use?
- Switches and high-speed ports: sFlow is usually the natural choice. Samples are immediate, and the header bytes help classification.
- Routers and firewalls: IPFIX or NetFlow v9 with a short active timeout. Prefer IPFIX if the device supports it.
- Legacy equipment: NetFlow v5 works for IPv4 volumetric detection, but plan to replace it.
- Mixed environments: a collector that accepts all three formats is more important than the format itself.
For DDoS detection specifically, protocol choice matters less than three things: a short reporting delay, a sampling rate suited to the link, and per-destination thresholds.
Where Nixcon fits
If you would rather not build and tune the collector yourself, NixMon is Nixcon's flow-based network monitoring and DDoS detection service. Nixcon operates its own network (AS40368), so the same flow-driven approach is used in production. Check the NixMon page for supported export formats and setup details for your equipment.
Frequently asked questions
Is IPFIX better than NetFlow for DDoS detection?
IPFIX is a standardized, more flexible successor to NetFlow v9. For detection it offers the same flow-record model, with better IPv6 and field coverage. In practice, timeouts and sampling rate affect detection speed more than the choice between NetFlow v9 and IPFIX.
Is sFlow faster than NetFlow at detecting attacks?
Usually yes, by default. sFlow sends samples as packets are seen, while NetFlow and IPFIX wait for flow timeouts. With the active timeout lowered to 60 seconds or less, the gap becomes small.
What sampling rate should I use for DDoS detection?
Start around 1:1000 on 1 to 10 Gbps links and raise N for faster links, such as 1:5000 to 1:10000 at 100 Gbps. Then check how many samples a small attack would produce per second and lower N on edge ports facing small services.
Can sampled flow data detect small attacks?
Large floods are detected reliably because they produce many samples. Low-rate attacks may produce only a few samples per second, so you need longer detection windows, a lower sampling rate on those ports, or complementary host-level monitoring.