数据包捕获:过滤 RX 与 TX

Jos*_*ler 8 linux tcpdump pcap interface

我有一个网络问题,其中源 MAC 与我的主机的源 MAC 之一匹配的帧到达主机 - 明显的重复 MAC、循环或其他 L2 问题。

我相信这是这种情况,因为我的 linux 网桥的 MAC 表(CAM 表)将本地 MAC(用于托管虚拟机)注册为在上游端口上,并且内核日志显示错误:

bridgename: received packet on bond0.2222 with own address as source address
Run Code Online (Sandbox Code Playgroud)

我想获得有关这些“流氓”数据包/帧的更多详细信息,但我不知道如何将它们归零。使用 tcpdump 您可以过滤特定的源 MAC( 'ether src MAC' ),但这是基于帧中的字节 - 而不是帧是“发送”还是“接收”。我们通常假设带有源 MAC 的帧意味着我们将其发送出去,但如果接收到重复的帧,则过滤器的内容看起来完全相同。

如何观察在数据包捕获中是接收帧还是发送帧?

小智 7

使用--directiontcpdump 选项:

-Q direction
--direction=direction
       Choose send/receive direction direction for which packets should be
       captured. Possible values are `in', `out' and `inout'. Not available on
       all platforms.
Run Code Online (Sandbox Code Playgroud)

  • @JoshuaMiller 我刚刚检查了 Ubuntu 14.04 上的“tcpdump”手册页,存在一个具有完全相同描述的选项,但它被称为“-P”而不是“-Q”(并且没有提到长形式)。 (2认同)

mc0*_*c0e 0

使用 iptables,您可以为传入和传出数据包提供不同的“链”。从 iptables(8) 手册页:

... the chains INPUT and OUTPUT are only traversed for packets coming into 
the local host and originating from the local host  respectively.   Hence 
every  packet  only  passes  through one of the three chains (except 
loopback traffic, which involves both INPUT and OUTPUT chains) ...
Run Code Online (Sandbox Code Playgroud)

iptables 可以做一些日志记录(-l),这可能会告诉你你需要什么。它可能还可以将数据包的副本转发到接口以使用其他工具进行日志记录,但我没有理由这样做。