简体   繁体   English

nftables - 在特定网桥上丢弃 arp 流量

[英]nftables - drop arp traffic on specific bridge

I have basic knowledge in nftables syntax and I am trying to drop all arp traffic that occurs on a Linux bridge.我对 nftables 语法有基本的了解,并且我正在尝试删除 Linux 网桥上发生的所有 arp 流量。

I am running debian and have several virtual machines which are all connected to one bridge.我正在运行 debian 并且有几个虚拟机都连接到一个网桥。 For a project I need to prevent any kind of ARP traffic but only on this bridge.对于一个项目,我需要阻止任何类型的 ARP 流量,但仅限于在这座桥上。

I tried something like我试过类似的东西

table bridge bridge_filter {
        chain forward {
                type filter hook forward priority 0;
                policy accept;

                iifname "tap2*" ether type arp drop;
                oifname "tap2*" ether type arp drop;

                iifname "vmbr1" ether type arp drop;
        }
}

(the virtual machines are automatically connected to the bridge with "tap2*" tap devices") but it doesn't work very well, at least I can still see ARP packets on each virtual machines with tcpdump, both request and reply. I know that the config above may not make sense completely but I couldn't figure out what's the right way. (虚拟机自动连接到带有“tap2*”tap devices”的网桥)但是效果不是很好,至少我仍然可以通过tcpdump看到每个虚拟机上的ARP数据包,请求和回复。我知道上面的配置可能完全没有意义,但我不知道什么是正确的方法。

Hope someone can help and maybe also explain what is wrong of my config.希望有人可以提供帮助,也许还可以解释我的配置有什么问题。 Greetings and thanks in advance.提前致以问候和感谢。

I'm not sure if you need to filter ARP traffic between just the VMs or also between the host and the VMs.我不确定您是否需要仅过滤 VM 之间的 ARP 流量,还需要过滤主机和 VM 之间的 ARP 流量。

If it's the latter then ARP traffic between the host and the VMs won't be filtered when using the "bridge forward" hook.如果是后者,则在使用“桥接转发”挂钩时,主机和 VM 之间的 ARP 流量将不会被过滤。

In order to filter unicast ARP traffic between the VMs and the host I think you'll need to also use a chain with the bridge "prerouting" and "postrouting" hooks.为了过滤虚拟机和主机之间的单播 ARP 流量,我认为您还需要使用具有桥接“预路由”和“后路由”挂钩的链。

For example例如

table bridge bridge_prerouting_filter {
        chain prerouting {
                type filter hook prerouting priority 0; policy accept;
                iifname "tap2*" ether type arp drop;
        }
}

table bridge bridge_postrouting_filter {
        chain postrouting {
                type filter hook postrouting priority 0; policy accept;
                oifname "tap2*" ether type arp drop;
        }
}

In regards to broadcast ARP traffic, that is going to be harder to selectively filter.关于广播 ARP 流量,选择性过滤将更加困难。 I don't know if the "oifname" parameter can be applied to broadcast traffic because the output interface is all interfaces.我不知道“oifname”参数是否可以应用于广播流量,因为输出接口是所有接口。

Filtering broadcast ARP traffic is going to be easier on the input side but it's going to be difficult to differentiate between broadcast ARP traffic that's allowed and ARP traffic that's not.在输入端过滤广播 ARP 流量会更容易,但很难区分允许的广播 ARP 流量和不允许的 ARP 流量。 There was supposed to be a new netdev "egress" filter in Linux 5.7 that might have been able to be used for this purpose but I think it's been removed. Linux 5.7 中应该有一个新的 netdev“出口”过滤器,它可能能够用于此目的,但我认为它已被删除。

Good luck!祝你好运!

Sorry for the late answer and possibly spare information about my goal.抱歉,回答晚了,可能还有关于我的目标的多余信息。 The goal was just to block all ARP traffic between several nodes in a network.目标只是阻止网络中多个节点之间的所有 ARP 流量。 This was an environment used for educational purposes where students should explore routing.这是一个用于教育目的的环境,学生应该在其中探索路由。 There were three virtual machines in a network.一个网络中有三台虚拟机。 Two of them should not be allowed to exchange ARP messages, the third one should be the middleman.其中两个不应该被允许交换 ARP 消息,第三个应该是中间人。 Therefore, I justed wanted to block ARP traffic between two specified nodes.因此,我只是想阻止两个指定节点之间的 ARP 流量。

I ended up with the following statements for each network:我最终得到了每个网络的以下语句:

iifname "tap201i0" oifname "tap203i0" ether type arp drop;
iifname "tap201i0" oifname "tap203i0" ip daddr 172.30.1.255 drop;
iifname "tap203i0" oifname "tap201i0" ether type arp drop;
iifname "tap203i0" oifname "tap201i0" ip daddr 172.30.1.255 drop;

(tap interfaces belong to virtual machines, 172.30.1.0/24 consists of nodes A, B and C) With these statements I achieved what I wanted. (tap接口属于虚拟机,172.30.1.0/24由节点A、B和C组成)通过这些语句我实现了我想要的。 The nodes A and C are not able to communicate via ARP (and broadcast IP) with each other.节点 A 和 C 无法通过 ARP(和广播 IP)相互通信。 Therefore they require node B to work as router, which still can communicate with A and B.因此他们需要节点 B 作为路由器,它仍然可以与 A 和 B 通信。

Hope this helps someone.希望这可以帮助某人。 The previous answer is what I wanted, I just wanted to show my final solution in case someone has the same goal.以前的答案是我想要的,我只是想展示我的最终解决方案,以防有人有相同的目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM