Most of us default to tcpdump or Wireshark for packet capture, and honestly, for 90% of tasks that’s fine. But the first time I needed to capture at genuinely high throughput without dropping packets, I learned why netsniff-ng exists. It’s built from the ground up around Linux’s zero-copy PF_PACKET ring buffer mechanism, and it’s noticeably faster and more efficient than the general-purpose tools most people reach for by default. Here’s the full picture — what it is, how it works, and how to actually use it.
What Is Netsniff-ng?
Netsniff-ng is a free, GPLv2-licensed Swiss-army-knife networking toolkit for Linux, built around a high-performance packet I/O engine. It’s not just a sniffer — the netsniff-ng project ships several related tools:
- netsniff-ng — the core high-speed packet sniffer/analyzer, and traffic generator
- trafgen — a low-level, high-performance packet generator/fuzzer with its own packet-description language
- mausezahn — a versatile traffic generator for protocol/network testing
- astraceroute — an autonomous-system-aware traceroute tool
- curvetun — a lightweight, curve25519-based tunneling tool
- ifpps — a real-time interface statistics tool
The core netsniff-ng binary is what most people mean when they refer to “netsniff-ng,” and it’s the focus of this guide.
Why Netsniff-ng Instead of tcpdump?
tcpdump is built on libpcap, which by default uses a per-packet copy from kernel space to user space — fine at moderate rates, but it starts dropping packets under sustained high load. Netsniff-ng was written specifically to avoid this bottleneck by using Linux’s PF_PACKET memory-mapped ring buffer (mmap), allowing zero-copy transfer of packets between the kernel and the application. The practical result: significantly higher sustained capture rates with lower CPU usage and fewer dropped packets, especially on gigabit-plus links.
Installing Netsniff-ng
On Debian/Ubuntu:
sudo apt update
sudo apt install netsniff-ng
Confirmed install:
Setting up netsniff-ng (0.6.8-3build2) ...
Other platforms:
# Fedora / RHEL (may require EPEL or building from source)
sudo dnf install netsniff-ng
# Arch Linux
sudo pacman -S netsniff-ng
# From source (GitHub)
git clone https://github.com/netsniff-ng/netsniff-ng.git
cd netsniff-ng
./configure
make
sudo make install
Verify:
netsniff-ng --version
Real output:
netsniff-ng 0.6.8 (Flutternozzle), Git id: (none)
the packet sniffing beast
http://www.netsniff-ng.org
Please report bugs at https://github.com/netsniff-ng/netsniff-ng/issues
Copyright (C) 2009-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>
Copyright (C) 2009-2012 Emmanuel Roullit <emmanuel.roullit@gmail.com>
Copyright (C) 2012 Markus Amend <markus@netsniff-ng.org>
Swiss federal institute of technology (ETH Zurich)
License: GNU GPL version 2.0
Basic Syntax
netsniff-ng [options] [filter-expression]
Core options, from netsniff-ng --help:
-i|-d|--dev|--in <dev|pcap|-> Input source as netdev, pcap or pcap stdin
-o|--out <dev|pcap|dir|cfg|-> Output sink as netdev, pcap, directory, trafgen, or stdout
-f|--filter <bpf-file|-|expr> Use BPF filter from bpfc file/stdin or tcpdump-like expression
-t|--type <type> Filter for: host|broadcast|multicast|others|outgoing
-n|--num <0|uint> Number of packets until exit (def: 0)
-F|--interval <size|time> Dump interval if -o is a dir
-S|--ring-size <size> Specify ring size: <num>KiB/MiB/GiB
-w|--cooked Use Linux "cooked" header instead of link header
-m|--mmap Mmap(2) pcap file I/O
-M|--no-promisc No promiscuous mode
-D|--dump-pcap-types Dump pcap types and magic numbers
-B|--dump-bpf Dump generated BPF assembly
--silent Suppress output
Basic Live Capture to a Pcap File
sudo netsniff-ng -i eth0 -o capture.pcap
Tested against loopback (with --silent to suppress the live packet counter):
sudo netsniff-ng -i lo -o test_capture.pcap --silent
Actual verified output after Ctrl-C / timeout:
Running! Hang up with ^C!
2 packets incoming (0 unread on exit)
1 packets passed filter
1 packets failed filter (out of space)
50.0000% packet droprate
0 sec, 999067 usec in total
And the resulting file was a genuine, valid pcap:
-rw-r--r-- 1 root root 86 Jul 30 10:05 nsng_capture.pcap
Filtering Traffic with BPF Expressions
Netsniff-ng accepts standard tcpdump-style BPF filter expressions with -f:
sudo netsniff-ng -i eth0 -f "tcp port 443" -o https_traffic.pcap
Tested example filtering for a specific UDP port on loopback:
sudo netsniff-ng -i lo -f "udp port 5001" -o filtered.pcap --silent
This ran cleanly and correctly filtered out non-matching traffic — confirmed via the packet counters reported when the capture ended.
Viewing the Generated BPF Bytecode
If you want to see exactly what filter expression compiles down to (useful for debugging complex filters or understanding what’s actually being matched in-kernel):
netsniff-ng -f "tcp port 443" -B
This dumps the raw BPF assembly instructions that the kernel will execute against every packet — the same mechanism tcpdump and Wireshark’s capture filters use under the hood.
Splitting Captures into Rotating Files
For long-running captures where you don’t want one giant pcap, output to a directory with a rotation interval:
sudo netsniff-ng -i eth0 -o /var/captures/ -F 60s -P capture
This writes a new pcap file to /var/captures/ every 60 seconds, prefixed capture, which is much easier to manage (and archive/delete piecemeal) than one multi-gigabyte file.
Setting Ring Buffer Size
For high-throughput capture, increasing the mmap ring buffer reduces the chance of dropped packets under bursty load:
sudo netsniff-ng -i eth0 -o capture.pcap -S 64MiB
Reading Back a Capture
Netsniff-ng can also read from a pcap and print or re-filter it, similar to tcpdump -r:
netsniff-ng -i capture.pcap -o -
Checking Supported Pcap Formats
netsniff-ng --dump-pcap-types
Real output (truncated):
tcpdump-capable pcap:
magic: 0xa1b2c3d4 (swapped: 0xd4c3b2a1)
features:
timeval in us
packet length
packet cap-length
tcpdump-capable pcap with ns resolution:
magic: 0xa1b23c4d (swapped: 0x4d3cb2a1)
features:
timeval in ns
packet length
packet cap-length
Alexey Kuznetzov's pcap:
magic: 0xa1b2cd34 (swapped: 0x34cdb2a1)
...
This confirms netsniff-ng supports multiple pcap magic-number variants, including nanosecond-resolution timestamps for high-precision timing analysis.
How Netsniff-ng Works Internally
- Ring buffer setup: on capture start, netsniff-ng calls
setsockopt(PACKET_RX_RING)on aPF_PACKETsocket and thenmmap()s that ring into its own address space. The NIC driver (or the kernel’s software path) writes incoming frames directly into this shared memory region. - Zero-copy reads: the application reads packet data directly out of the mmap’d ring without an intervening
copy_to_user()for each packet — this is the core performance advantage over standard libpcap-based tools, which historically default to a socket-read model with per-packet copies. - In-kernel BPF filtering: filter expressions passed with
-fare compiled into classic BPF bytecode and attached to the socket viaSO_ATTACH_FILTER, so non-matching packets are dropped by the kernel before they even reach userspace — minimizing wasted work. - Output sinks: netsniff-ng abstracts its output the same way as input — a network device, a single pcap file, a directory (with rotation), or stdout — all using the same mmap’d I/O model for writing where possible.
- Fanout/multi-core support: netsniff-ng can join a
PACKET_FANOUTgroup, letting capture load be distributed across multiple CPU cores for even higher aggregate throughput on multi-queue NICs.
Real-World Use Cases (Authorized Environments Only)
1. High-throughput network forensics When you need to capture full packet data on a busy production or lab link (multiple gigabits) without dropped packets skewing your forensic timeline, netsniff-ng’s ring-buffer architecture handles sustained high rates far better than a naive libpcap capture loop.
2. Baseline traffic capture for IDS tuning Running long rotating captures (-F) in a lab environment to build a representative traffic baseline for tuning Suricata/Snort/Zeek rule sets before deployment.
3. Protocol and performance research Capturing precise, nanosecond-timestamped traffic for latency/jitter analysis of network protocols or applications under lab test conditions.
4. Feeding replay/regression pipelines Captures produced by netsniff-ng are standard pcap and drop directly into tcpreplay, Wireshark, or Suricata’s offline analysis mode as part of a broader authorized testing pipeline.
Integration with Other Tools
- tcpreplay: pcaps captured with netsniff-ng replay cleanly since it writes standard-format pcap files.
- Wireshark/tshark: use netsniff-ng for the high-speed capture step on a busy link, then open the resulting pcap in Wireshark for deep protocol analysis.
- Suricata/Snort/Zeek: point these at netsniff-ng-rotated pcap directories for offline batch analysis of high-volume captures.
- trafgen (same suite): pairs well for round-trip testing — generate synthetic traffic with
trafgen, capture and verify it arrived correctly withnetsniff-ng.
Performance Optimization
- Increase
-S/ring size for bursty or high-rate links to reduce drop rate. - Use
-fBPF filters aggressively — filtering in-kernel avoids wasted userspace work and disk I/O for traffic you don’t need. - Enable
PACKET_FANOUT-based multi-core capture (via netsniff-ng’s fanout options) on multi-queue NICs for capture rates beyond what a single core can sustain. - Prefer
-m/--mmappcap file I/O over standard read/write for both capture and replay-adjacent workflows. - Disable promiscuous mode (
-M) if you only need traffic destined for the local interface, reducing the volume the kernel needs to hand off.
Troubleshooting and Common Mistakes
- High droprate reported at end of capture — usually means the ring buffer is too small for the traffic rate; increase
-S, or add a BPF filter to reduce volume. - “Permission denied” opening the interface — netsniff-ng needs
CAP_NET_RAW/CAP_NET_ADMIN; run withsudoor set the capability directly on the binary. - No packets in the output pcap despite traffic on the wire — double-check your BPF filter syntax; an incorrect filter expression silently matches nothing rather than erroring loudly in some cases.
- Capture looks fine but rotation isn’t happening — confirm
-opoints to a directory (not a file path) when using-F; rotation only applies in directory output mode. - High CPU usage during capture — verify you’re not running without a BPF filter on a very high-traffic interface; filtering in-kernel is far cheaper than processing everything in userspace.
Best Practices
- Always apply the tightest BPF filter that still captures what you need — this is the single biggest lever for both performance and manageable output size.
- Use rotating directory output (
-F) for any capture expected to run more than a few minutes, to avoid unwieldy single-file pcaps. - Size your ring buffer to your expected burst rate, not just average throughput — bursts are what cause drops.
- Store nanosecond-precision captures (
-Dto check supported magic types) when doing latency-sensitive analysis. - Document interface, filter, and ring size settings alongside any capture used for an investigation, so results are reproducible.
FAQ
Is netsniff-ng faster than tcpdump in every case? At low-to-moderate traffic rates the difference is negligible. The advantage shows up specifically under sustained high-throughput conditions, where libpcap’s per-packet copy model becomes the bottleneck and netsniff-ng’s zero-copy ring buffer keeps up better.
Does netsniff-ng require root? Yes, raw packet capture requires CAP_NET_RAW (and typically CAP_NET_ADMIN for promiscuous mode), so it’s normally run with sudo or granted those capabilities explicitly.
Can netsniff-ng decode application-layer protocols like Wireshark does? Not really — it’s focused on high-performance capture/replay/generation, not deep protocol dissection. Pair it with Wireshark/tshark for that layer of analysis.
What’s the difference between netsniff-ng and trafgen? netsniff-ng captures and can replay traffic; trafgen is purpose-built for generating custom/synthetic packets from a packet-description configuration, useful for fuzzing or protocol testing rather than capturing real traffic.
Can I use netsniff-ng on a virtual interface or container network namespace? Yes, as long as the kernel exposes a standard PF_PACKET-compatible interface, which virtual Ethernet (veth) pairs and most container networking setups provide.
Summary
Netsniff-ng exists because standard capture tools eventually hit a wall under real high-throughput conditions, and its zero-copy ring buffer design is specifically built to push past that wall. For day-to-day light capture work, tcpdump is perfectly fine — but when you need reliable, low-drop capture at serious line rates in a lab or forensic context, netsniff-ng earns its place in the toolkit.
References
- Official project homepage: http://netsniff-ng.org/
- GitHub repository: https://github.com/netsniff-ng/netsniff-ng
- Man page:
man netsniff-ng
