brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tcpdump -w saves a capture you can open in Wireshark later

Linux
~/tips/tip-networking-tcpdump-w-capture-file

sudo tcpdump -i any -n -c 500 -w /tmp/capture.pcap host 192.168.1.50 and port 443

Records packets to a file with a filter and a packet limit for later analysis.

Watching packets scroll by in a terminal is hard when the problem comes and goes. I would rather record a short capture on the server and read it calmly on my Mac.

Write the packets to a file instead of the screen:

sudo tcpdump -i any -n -c 500 -w /tmp/capture.pcap host 192.168.1.50 and port 443

Here -i any listens on all interfaces, -n skips name lookups, -c 500 stops after 500 packets, and -w writes the raw packets to a file. The filter at the end keeps the file small. Read it back on the server with tcpdump -nr /tmp/capture.pcap, or copy it to another machine and open it in Wireshark.

On a longer run, -C 50 starts a new file after about 50 million bytes, and -G 3600 starts one every hour, with a time format in the file name so files do not overwrite each other. The output is buffered, so add -U if you read the file while it is still being written.

Caveats: a capture holds whatever crossed the wire, which can include passwords and tokens, so delete it when you are done and share it carefully. Capturing needs root, and -Z lets tcpdump drop to another user once the capture has started.

Further reading: tcpdump man page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link