首页 > 解决方案 > Tcpdump 通过文件轮换将 pcap 写入远程服务器

问题描述

我正在尝试在 linux 机器上运行 tcpdump,它需要在远程服务器上写入 pcap,每 10 秒轮换一次文件。

tcpdump -s0 -i eth0 -G 10 -w - | ssh {remote_ip} "cat > capture_%d-%m_%Y__%H_%M.pcap"

该文件在第一个周期(10 秒)在远程服务器上返回,然后我收到以下错误。

tcpdump: listening on ens224, link-type EN10MB (Ethernet), capture size 262144 bytes
tcpdump: Can't write to standard output: Bad file descriptor

我正在使用-G基于时间的轮换,如果我删除-G,那么我可以连续写入远程服务器。

我的远程服务器配置为此主机的无密码登录。

标签: linuxbashshelltcpdump

解决方案


您可以通过管道将 tcpdump 传输到另一个 tcpdump,因此在您的情况下:

tcpdump -i eth0 -w - not port 22 | \
     ssh my.remote.host tcpdump -r - -w /tmp/capture_%d-%m_%Y__%H_%M_%S.pcap  -G 2 -C 100

推荐阅读