Tcpdump通过文件旋转将pcap写入远程服务器

问题描述 投票:0回答:1

我正在尝试在Linux机器上运行tcpdump,该机器需要每10秒旋转一次在远程服务器上写入pcap。

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,则可以连续写入远程服务器。

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

linux bash shell tcpdump
1个回答
0
投票

您可以将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
© www.soinside.com 2019 - 2024. All rights reserved.