An intermittent network fault can take hours to recur, even though the traffic around it lasts only a few seconds. On the Linux desktop, Wireshark can capture into a ring buffer that keeps recent packets in a limited number of files.

A file size threshold controls when Wireshark starts the next file. The file count controls how many segments stay on disk, including the one being written. On a busy interface, the same settings retain a shorter span of traffic.

Wireshark adds a timestamp and a sequence number to each capture filename. The sequence numbers show how much of the capture has rolled out of the set once the oldest file is replaced.

Steps to capture packets with a ring buffer in Wireshark:

Use your normal Linux account with permission to capture on the interface that carries the traffic. Capture only traffic you are allowed to inspect. Use an empty, writable folder under your home directory and keep it private because captures can contain credentials and packet payloads.

Start with no capture running and Capture Options at their defaults. The capture filter is blank, automatic stop is off, and the Output tab has Create a new file automatically… and the packet-count, size, time and when time is a multiple of boxes clear.

  1. Open Wireshark from the Activities search.
  2. Click the Capture Options gear in the toolbar.
  3. Select the interface that carries the traffic you need, such as Loopback: lo for traffic between programs on the same computer.
  4. Select the Output tab.
  5. Enter the absolute path for the new capture in File.

    The example uses /home/reader/Documents/captures/traffic.pcapng.

  6. Enable Create a new file automatically….
  7. Enable the after checkbox on the row with the file-size unit.
  8. Click the number in the file-size row.
  9. Replace the number with your chosen size threshold, using 1 for the worked example.
  10. Open the unit menu beside the size field.
  11. Choose the unit for your threshold, such as megabytes for the worked example.

    A finished segment can be slightly larger than the threshold.

  12. Enable Use a ring buffer with.
  13. Click the file count beside Use a ring buffer with.
  14. Replace the file count with the number of files you want to retain, using 3 for the worked example.
  15. Click Start to begin capturing into the ring.

    Once the ring is full, each new segment removes the oldest file. With a limit of three, starting file 00004 removes file 00001.

  16. Press Ctrl+Alt+T to open a terminal on Ubuntu once Wireshark shows that it is capturing from the selected interface.
  17. Run the rate-limited download through the selected interface with your own file URL.

    The minimum download size is the size threshold times the ring count plus one more threshold. For three 1 MB files, use a download of 4 MB or more. The –limit-rate 512k option paces the download so Wireshark can keep up, and -o /dev/null discards the downloaded file. The example uses a 4 MiB file on Loopback: lo.

    curl --limit-rate 512k -o /dev/null http://www.example.test/files/sample-4mb.bin
  18. Return to Wireshark with Alt+Tab once the terminal prompt comes back.
  19. Click Stop after the download finishes.
  20. Open the File menu once the window title shows a numbered capture filename.
  21. Point to File Set in the File menu.
  22. Choose List Files from the File Set submenu.
  23. Confirm that Files in Set lists as many files as your ring count and that the earliest sequence number is higher than 00001.

    In the example, the remaining files are numbered 00003 through 00005. For a real fault, use the same settings with a size threshold and file count that fit your traffic and disk budget, and click Stop once the fault has recurred so the ring keeps the newest files.

Share this guide