1

我对 nftables 语法有基本的了解,我正在尝试删除 Linux 网桥上发生的所有 arp 流量。

我正在运行 debian 并且有几个虚拟机都连接到一个网桥。对于一个项目,我需要阻止任何类型的 ARP 流量,但只能在这个网桥上。

我尝试了类似的东西

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;
        }
}

(虚拟机通过“tap2*”tap devices“自动连接到网桥)但是效果不是很好,至少我仍然可以看到每个虚拟机上的 ARP 数据包 tcpdump,请求和回复。我知道上面的配置可能不完全有意义,但我不知道什么是正确的方法。

我的配置有什么问题?

4

2 回答 2

1

我不确定您是否需要仅过滤虚拟机之间的 ARP 流量,或者还需要过滤主机和虚拟机之间的 ARP 流量。

如果是后者,那么在使用“桥接转发”挂钩时,主机和虚拟机之间的 ARP 流量将不会被过滤。

为了过滤虚拟机和主机之间的单播 ARP 流量,我认为您还需要使用带有“prerouting”和“postrouting”钩子的链。

例如

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;
        }
}

关于广播 ARP 流量,这将更难选择性过滤。我不知道“oifname”参数是否可以应用于广播流量,因为输出接口是所有接口。

在输入端过滤广播 ARP 流量将更容易,但很难区分允许的广播 ARP 流量和不允许的 ARP 流量。Linux 5.7 中应该有一个新的 netdev“出口”过滤器,它可能可以用于此目的,但我认为它已被删除。

于 2021-10-21T22:46:29.603 回答
0

目标只是阻止网络中几个节点之间的所有 ARP 流量。这是一个用于教育目的的环境,学生应该在其中探索路由。一个网络中有三个虚拟机。其中两个不应该被允许交换 ARP 消息,第三个应该是中间人。因此,我只是想阻止两个指定节点之间的 ARP 流量。

我最终为每个网络提供了以下语句:

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. The nodes A and C are not able to communicate via ARP (and broadcast IP) with each other. Therefore they require node B to work as router, which still can communicate with A and B.

The previous answer is what I wanted, I just wanted to show my final solution in case someone has the same goal.

于 2021-12-11T23:08:51.220 回答