关于 nftables chain 优先级的问题

2022-03-30 19:00:44 +08:00
 yaott2020

现在有以下规则:

table inet filter2 { # handle 39
        set iplist4 { # handle 3
                type ipv4_addr
        }

        set iplist6 { # handle 4
                type ipv6_addr
        }

        chain filter { # handle 12
                type filter hook input priority filter + 1; policy accept;
                ip saddr @iplist4 accept # handle 13
                ip6 saddr @iplist6 accept # handle 14
                drop # handle 16
        }
}
table ip default_filter { # handle 42
        chain filter { # handle 4
                type filter hook input priority filter; policy accept;
                tcp dport 8092 accept # handle 5
        }
}

若是按上面设置,则无法访问 TCP 8092 端口,去掉 filter2 == filter == drop 规则后,TCP 8092 端口访问正常

请教:priority 设置优先级且数字越小优先级越高,而按照我的设置则无法屏蔽所有端口(除 TCP 8092 外),请问我哪里设置错了

1372 次点击
所在节点    问与答
9 条回复
24owls
2022-03-30 20:18:03 +08:00
nft(8) -> STATEMENTS -> VERDICT STATEMENT -> accept

Terminate ruleset evaluation and accept the packet. The packet can still be dropped later by another hook, for instance accept in the forward hook still allows to drop the packet later in the postrouting hook, or another forward base chain that has a higher priority number and is evaluated afterwards in the processing pipeline.

注意最后一小句
plko345
2022-03-30 21:21:52 +08:00
nftables 好用吗?学了些,一直没用,还在用 iptables
yaott2020
2022-03-30 21:25:11 +08:00
那如何终止匹配后面的呢
yaott2020
2022-03-30 21:25:49 +08:00
@plko345 比 iptables 复杂一些,不太好学
24owls
2022-03-30 21:59:59 +08:00
> 那如何终止匹配后面的呢

没什么特别好的办法,要么把它们放到或连到同一个 base chain 上,要么先在低优先级 chain 上做个 mark 再在高优先级上根据 mark 价格特殊情况
yaott2020
2022-03-30 22:03:20 +08:00
@24owls 感觉 accept 这么设置好蠢啊,算了,还是打 mark 再说吧
yaott2020
2022-03-30 22:18:02 +08:00
好心累,还是不行

```
table inet default { # handle 47
chain filter { # handle 1
type filter hook input priority filter; policy accept;
tcp dport 8092 meta mark set 0x000000fb # handle 4
}
}
table inet SafeFortress { # handle 49
set iplist4 { # handle 2
type ipv4_addr
flags interval
}

set iplist6 { # handle 3
type ipv6_addr
flags interval
}

chain filter { # handle 1
type filter hook input priority filter + 1; policy accept;
meta mark 0x000000fb return # handle 4
ip saddr @iplist4 accept # handle 5
ip6 saddr @iplist6 accept # handle 6
drop # handle 7
}
}
```
24owls
2022-03-30 22:55:04 +08:00
@yaott2020 你上面的配置还有一个更大的问题,这条规则 inet SafeFortress filter drop # handle 7 同时还把对端的 TCP packet 给 drop 了

你还得要么把对端 IP 加到允许的 IP 列表,要么允许 tcp sport 8092 通过,要么允许 ct state { established, related } 通过
yaott2020
2022-03-31 18:58:00 +08:00
放弃了。。。还是 iptables 好用

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/843944

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX