NetFlow from a Linux Router with softflowd and nfdump: Top Talkers, Filters and What It Misses

Packet captures answer “what is in this packet”. Flow records answer the question I get asked more often: “who is using the link, and for what?” You do not need a Cisco box or a commercial collector to learn how that works. A Linux router, softflowd and nfdump will do the lot.

I built a small client, router and server lab with network namespaces on my Debian 13 test VM, generated a realistic mix of traffic and queried the result. All output below is from that lab.

The pieces

sudo apt install softflowd nfdump
softflowd 1.1.1-1
nfdump 1.7.5-2+deb13u1

Three roles:

  • softflowd watches an interface, groups packets into flows and exports them as NetFlow or IPFIX. It is the “router” side. Physical routers do this in hardware.
  • nfcapd is the collector. It listens for exports and writes them to files, rotating on a timer.
  • nfdump reads those files and filters, aggregates and ranks them.

One Debian detail: installing nfdump also enables and starts a default nfdump@default collector on port 2055. If you want to run your own collector, stop and disable it first, or yours will not be able to bind the port:

sudo systemctl disable --now nfdump@default

The lab

cl (10.10.1.2) ---- r0 [rt] r1 ---- sv (10.10.2.2)

The router namespace rt forwards between the two networks, and softflowd watches the client-facing interface r0. Collector and exporter share the router namespace, talking over loopback.

# collector: files in /tmp/nf (use a separate directory with nothing else in it), rotate every 10 s
nfcapd -w /tmp/nf -b 127.0.0.1 -p 2055 -t 10 -I rt1 -P /tmp/nf/nfcapd.pid

# exporter: NetFlow v9, flows end after 30 s at most, check expiry every 5 s
softflowd -i r0 -n 127.0.0.1:2055 -v 9 -t maxlife=30 -t expint=5 \
  -c /tmp/nf/sf.ctl -p /tmp/nf/sf.pid

-t 10 on nfcapd is short for the lab. The default is 300 seconds, so in production a flow shows up in a readable file within five minutes at worst. The smallest rotation interval nfcapd accepts is 2 seconds.

The traffic

From the client I generated:

  • one 200 MB TCP transfer with iperf3
  • 30 connections to port 80, 12 to port 443 and 3 to port 22 (small request and response)
  • 40 UDP queries to port 53
  • 20 pings

That is 182 flow records for roughly 7,000 packets.

Reading the records

The summary first:

$ nfdump -R /tmp/nf -I
Flows: 182
Flows_tcp: 98
Flows_udp: 80
Flows_icmp: 4
Packets: 7170

Then individual records:

$ nfdump -R /tmp/nf -o line -c 4
Date first seen         Duration  Proto  Src IP Addr:Port       Dst IP Addr:Port  Packets  Bytes Flows
2026-11-02 20:54:31.597 00:00:00.003 TCP  10.10.1.2:57226 ->     10.10.2.2:80           5     273     1
2026-11-02 20:54:31.597 00:00:00.003 TCP  10.10.2.2:80    ->     10.10.1.2:57226        5    2268     1

Look at the two lines. One TCP conversation is two flow records, one per direction, with 5 packets and 273 bytes of request against 5 packets and 2,268 bytes of response. Flows are unidirectional. Filtering on a service port will give you half the picture unless you account for the reverse record, which is why the next query matters.

Top talkers

Rank destination ports by bytes:

$ nfdump -R /tmp/nf -s dstport/bytes -n 5 -q
 ...  any   5201     4( 2.2)   3608(50.3)  161.9 M(99.8)
 ...  any  46868     1( 0.5)   2975(41.5)  154708( 0.1)
 ...  any     80    30(16.5)    150( 2.1)    8190( 0.0)
 ...  any    443    12( 6.6)     60( 0.8)    3276( 0.0)

Port 5201 (iperf3) is 99.8% of the bytes, in 2.2% of the flows. That is the classic shape of a real network: a handful of elephant flows carry the bytes. Then rank the same traffic by flow count:

$ nfdump -R /tmp/nf -s dstport/flows -n 5 -q
 ...  any     53    40(22.0)     40( 0.6)   1230( 0.0)
 ...  any     80    30(16.5)    150( 2.1)    8190( 0.0)
 ...  any    443    12( 6.6)     60( 0.8)    3276( 0.0)
 ...  any   5201     4( 2.2)   3608(50.3)  161.9 M(99.8)

By flows, DNS on port 53 leads, with 40 flows and almost no bytes. A scanner or a misbehaving application stands out in this view, not in the bytes view. Use both rankings.

One quirk: with -s dstport the reverse direction of a conversation appears with the client’s ephemeral port as the “destination”, which is why odd high ports such as 46868 show up in the list. Filter by proto and dst port when you want clean answers.

Filters

The filter language reads like a sentence:

$ nfdump -R /tmp/nf 'proto udp and dst port 53' -a -A srcip,dstip -q
... 10.10.1.2  10.10.2.2   40 flows   1230 bytes

$ nfdump -R /tmp/nf 'proto icmp' -o line -q
ICMP  10.10.1.2:0 -> 10.10.2.2:8.0    20 pkts  1680 bytes
ICMP  10.10.2.2:0 -> 10.10.1.2:0.0    20 pkts  1680 bytes

$ nfdump -R /tmp/nf 'bytes > 1000000' -o line -q
TCP  10.10.1.2:46868 -> 10.10.2.2:5201   3593 pkts  161.9 M bytes

$ nfdump -R /tmp/nf 'dst port 22' -o long -c 2 -q
TCP  10.10.1.2:58144 -> 10.10.2.2:22  ...AP.SF   0   5   273   1

-a -A srcip,dstip aggregates 40 DNS flows into one line per address pair, and -o long adds TCP flags (...AP.SF: ACK, PSH, SYN, FIN). The ICMP record shows the type and code in the port field, 8.0 for an echo request.

When pointing -R at a directory, make sure it contains only nfcapd files. My first queries printed Open file '/tmp/nf/nfcapd.out': bad magic because I had left a log file in the same directory.

What this flow data does not tell you

Two things I measured, and both matter if you plan to rely on it.

1. Large flows get split. On a first, uncapped run, iperf3 pushed about 8 GB through at 16.7 Gbit/s. softflowd’s statistics showed:

Flow bytes:          2149459624    2149511036    2149599140
over 2 GiB =         3

Each of three flows was cut at about 2 GiB (2,149,xxx,xxx bytes) and exported as a separate record, so one transfer is several records. When you sum bytes per conversation this is harmless, but if you count flows to approximate “connections”, long, heavy transfers will inflate it.

2. A software exporter can miss packets. After the lab run, softflowd reported:

Packets processed: 320994
Packets received by libpcap: 335434
Packets dropped by libpcap: 13848

About 4% of packets were dropped by the capture before softflowd ever saw them. The 200 MB iperf3 transfer shows up in the records as 161.9 MB. The totals are in the right order of magnitude, and the top-talker ranking was correct, but the byte counts are not billing grade. Hardware exporters do not have this problem, a software one on a busy box does. In my lab the transfer ran at multi-gigabit speed on two vCPUs, which is far harder than most real links, so your result will be better, but check the counter on yours:

softflowctl -c /tmp/nf/sf.ctl statistics | grep -E "Packets processed|dropped"

What I would do with it

  • Run it at the edge, on the interface facing the users.
  • Rotate with the default five minutes and keep a few weeks of files. They are small: 182 records are a few hundred bytes of file.
  • Use the two top-N queries (bytes and flows) as your first answer to “what is using the link” and “what is unusual”.
  • Treat counts as estimates and check softflowctl statistics for drops.

NetFlow will not show you payload, but it will tell you which machine talked to which, when, and how much. Most “what happened on the network” questions are answered by exactly that.