Linux – How to make tcpdump stop the capture after a certain number of packets captured

linuxtcpdump

I am debugging a problem where two servers get stuck in a loop when communicates with each other. After a server restart the problem will start at some point, it can be in an hour
or in a day. I want to tcpdump the traffic when the problem starts so I can find out what
makes it happen.

My plan is to restart the servers then let tcpdump capture the traffic and then analyze the
result. However I would like tcpdump to stop after a few thousand packets captured to
avoid having to monitor it, since I don't know when the traffic will start.

Anyone having a suggestion?

Best Answer

See man tcpdump:

-c Exit after receiving count packets.