How to capture tcpdump to a compress file in linux

Yasiru G picture Yasiru G · May 19, 2016 · Viewed 7.5k times · Source

I have a DNS server and I want to capture DNS traffic to get all the IPs which use my DNS server.

For this I start using following tcpdump command and capture them to a file:

tcpdump -n -i eth0 dst port 53 >> dns_data.log

But the file size is high when I run this for long time. How can I capture this to a compress file? I tried below command but its not working.

tcpdump -n -i eth0 dst port 53 | bzip2 -c >> dns_data.bz2

Answer

Anatoliy Orlov picture Anatoliy Orlov · May 19, 2016

Try something like tcpdump -G 3600 -w 'trace_%Y-%m-%d_%H:%M:%S.pcap' -z gzip

-G N means rotate every N (3600) seconds. -z command means run command(gzip) after rotation.