How to Rotate Packet Capture Files with dumpcap

A packet capture can fill a disk quickly when a network is busy. Dumpcap can write a series of files and reuse the oldest slot in a ring buffer, retaining recent traffic for troubleshooting without accumulating files indefinitely. Set the rotation threshold and file count together: a threshold alone creates more files, while a count without a threshold does not tell dumpcap when to switch.
Capture only traffic you are authorized to inspect. Packet files can contain addresses, credentials, session data, and application payloads. Decide where the files will be stored, who can read them, how long they can be retained, and which evidence must be preserved before starting a ring that will overwrite older data.
Select an Interface and Check Capture Permissions
Use the dumpcap executable installed with Wireshark or your system's capture-tools package. Run dumpcap -v to check the installed version and dumpcap -D to list capture interfaces. Choose the interface that carries the traffic relevant to your question; the default interface may be wrong on a host with Wi-Fi, Ethernet, VPN, and virtual adapters. Use -i with the displayed interface name or number.
Check the installed dumpcap -h output because supported flags and capture driver behavior can vary by release and platform. Packet capture may require elevated privileges or capture-group membership. Grant only the access needed on the system you administer.
Create a dedicated output directory with restricted read access and enough free space, then run the examples from that directory. Use a new base filename for each capture session to avoid confusing files from different runs. The -w option sets the base output filename. Avoid storing packet data in a web-served directory or a shared temporary folder.
Apply a Narrow Capture Filter
A capture filter limits packets before they are written, reducing data volume and exposure. Dumpcap uses -f for a pcap-style filter expression. For example, tcp port 443 selects TCP packets whose source or destination port is 443. The filter may still include unrelated connections and encrypted payload bytes.
Quote a filter containing spaces as one argument in your shell. Confirm the filter grammar and direction for your environment rather than copying a broad expression without review.
Choose the smallest set of hosts, ports, and protocols that can answer the troubleshooting question. A capture filter is different from a display filter applied later in Wireshark: packets excluded at capture time cannot be recovered from these files. Test the filter with a short authorized capture and confirm it includes the traffic you need. If you need fewer bytes from each packet, -s 128 limits each saved packet to at most 128 bytes. Choose the length for the analysis you need: truncation can remove useful protocol fields and still leave sensitive headers or payload.
Set the Rotation Threshold
Use -b filesize:VALUE for a size threshold in decimal kilobytes, where 1 kB is 1,000 bytes. Use -b duration:SECONDS to rotate after each file has been open for the specified time. You can combine the two thresholds so a file closes when either condition is reached, limiting growth during traffic spikes while still rotating quiet captures.
The following example keeps up to five files and switches after each reaches approximately 10 MB. Replace interface 1 and the filter with the values appropriate to your authorized capture:
dumpcap -i 1 -f "tcp port 443" -w capture.pcapng -b filesize:10000 -b files:5Each criterion needs its own -b option. The files receive sequence numbers and creation timestamps, so the output consists of names derived from capture.pcapng rather than one file with that exact name.
To rotate every minute, replace the size criterion with -b duration:60, keeping -b files:5. For both limits, retain the size criterion and add the duration criterion. A time limit alone does not bound the file size on a busy interface.
Five one-minute files do not guarantee five complete minutes of history. At each rotation of a full ring, the oldest completed file is removed before the new file has recorded a full minute. With a size threshold, the retained time varies further with the amount of matching traffic.
Cap the Ring-Buffer File Count
The -b files:COUNT criterion turns multiple-file capture into a ring. After the ring reaches that count, each subsequent rotation removes the oldest file and opens a new file in its place. Without files, the tool can continue creating files until another stop condition is met or the disk fills.
For the size-based example, five 10 MB files give a nominal budget of 50 MB, about 47.7 MiB. The active file is already included in the count of five. Leave extra space for threshold overshoot and filesystem allocation.
The ring does not reserve disk space in advance. Keep enough free space for the operating system, logs, and other files on the volume. Check available space during a long capture, since another process can consume the margin even when the ring size remains stable.
Check Drops and Timestamps
Watch the capture status and resulting files during a small controlled test. Confirm that filenames and timestamps advance, the count stops growing at the selected limit, and the oldest capture is replaced after another rotation. Compare file modification times and sizes rather than relying only on name order. Packet timestamps depend on the capture system's clock and timestamp source. When correlating a capture with service logs, account for clock differences between the systems.
Review packet counts and drop statistics where the capture driver provides them. The separate dumpcap -S mode prints interface statistics; it does not run a file capture and cannot be combined with ring-buffer capture. For the recording itself, inspect the capture summary and any available interface statistics saved in the pcapng file.
A ring that writes five files correctly can still lose packets under load. If packets are being dropped, try a larger capture buffer, such as -B 8 for 8 MiB, and repeat the short test. The operating system or driver may limit the allocation, and a larger buffer cannot make a persistently slow disk keep up.
Use small thresholds during the initial rotation test so replacement happens quickly. Restore the intended capture limits afterward and monitor free space as well as reported drops. Missing drop statistics are not proof that no packets were lost.
Stop the Capture and Preserve the Required Files
Press Ctrl+C in the capture terminal once the needed window has been recorded, and wait for dumpcap to finish. To stop a session automatically after ten minutes, add -a duration:600 to its command before starting. After dumpcap exits, copy the required files to a separate archive directory. Keep the completed capture files until you have verified the copies.
Preserve the files' time range and a checksum if you need to verify that the archived copies remain unchanged. Limit access, set a retention date, and redact payloads or identifiers before sharing. Do not upload raw packet files to a public location.
If the ring has already overwritten the incident window, the later files cannot recreate the missing packets.







