The kernel has a buffer for packets to be delivered to tcpdump. If tcpdump doesn't respond quickly enough, the kernel will overwrite old packets with new ones.
使用tcpdump抓包时,内核分配缓冲区存放向tcpdump传送的数据包,如果tcpdump处理的不够快,新到达的包会覆盖缓冲区中较早的包,即出现dropped丢包的情况。
解决方法:
1. 增大系统缓冲区大小 bpfbufsize
2. 避免tcpdump进行dns解析,使用tcpdump -n参数。尽量减少tcpdump的工作量,其他的参数如-nn等可参考。
-
Dropped packets
- At the end of its run, TCPdump will inform you if any packets were dropped in the kernel. If this becomes a problem, it's likely that your host can't keep up with the network traffic and decode it at the same time. Try using TCPdump's -w option to bypass the decoding and write the raw packets to a file, then come back later and decode the file with the -r switch. You can also try using -s to reduce the capture snapshot size.