linux - nftables中表/链的顺序是怎么排列的?

标签 linux networking firewall

比如我有两个表:

table inet filter2 {
  chain forward {
    type filter hook forward priority 0; policy accept;
    ct state established,related accept
    iifname $wireif oifname $wirelessif accept
  }
}

table inet filter {
  chain forward {
    type filter hook forward priority 0; policy accept;
    drop
  }
}

filter 首先执行,所以我所有的转发数据包都被丢弃,这不是我想要的。如何设置最后执行的表/链使其作为默认选项?

最佳答案

Nftables 使用底层 netfilter 框架 has 6 hooks points位于 linux 内核网络堆栈的不同位置。

当一个或多个规则被添加到同一个 Hook 点时,netfilter 框架按照规则的 priority type 对规则进行优先级排序。 .

例如,在您添加链的情况下,您可以为每个链使用不同的优先级类型。 比方说你想给予规则定义的 forward chain of

更高的优先级

filter tablefilter2 tableforward chain

.

nft add table ip filter2

nft add chain ip filter2 forward {type filter hook forward priority 0 \;}

现在给 filter 表的 forward chain 赋予更高的优先级,分配优先级小于 0。

nft add table inet filter

nft add chain inet filter '{type filter hook forward priority -1 }'

这里较高的优先级值意味着较低的优先级,反之亦然。

但是在使用不同的优先级类型时要小心,因为它有时可能会导致数据包出现意外行为。更多信息请阅读 this

PS:有轻微different syntax for negative priority .

关于linux - nftables中表/链的顺序是怎么排列的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38162173/

相关文章:

linux - 如何更改挂载点名称?

linux - 如何在 awk 操作中增加 shell 变量

linux - 是否可以使用 eBPF 来阻止内核空间中的恶意进程?

c# - Windows 服务器 2008 : Is opening smtp port not enough for sending mail?

linux - 将虚拟机升级到 debian 8 jessie 后,Proxmox 虚拟机未加载

c++ - 为树莓派交叉编译 bcm2835-1.42 库。

networking - 网络流量嗅探时有什么办法可以过滤Hadoop数据包吗?

networking - TCP中的流量控制和拥塞控制有什么区别?

iphone - iOS获取当前wlan网络名称

c++ - 如何正确使用 INetSharingManager?