例如:
#!/usr/sbin/nft -f
add table ip filter_4
add chain ip filter_4 input {
type filter hook input priority filter; policy drop;
}
add chain ip filter_4 new_in_4 {
comment "New input IPv4 traffic"
}
# Note it's goto not jump! (thus no way out of new_in_4 chain)
add rule ip filter_4 input ct state new goto new_in_4
# Is this block drop or accept rule?
add rule ip filter_4 new_in_4 log prefix "some comment: "
Run Code Online (Sandbox Code Playgroud)
该规则没有明确accept或drop判决,那么哪个是默认的?
\n\n该规则没有明确
\naccept或drop判决,那么哪个是默认的?
没有任何。规则不需要有最终裁决 \xe2\x80\x93 如果您没有指定,则它没有最终裁决。数据包处理将继续到下一条规则。
\n如果数据包到达您所做的链的末尾goto,则结果就好像它到达父链 \xe2\x80\x93 的末尾,在这种情况下,“输入”链具有policy drop,因此将应用。
(换句话说,有一条出路离开新链,就像有一条出路离开“输入”链 \xe2\x80\x93 一样,链策略可以被认为位于调用堆栈的开头,并且是您将“返回”的最终位置。使用“jump”时,堆栈将是policy > chain input > chain new_in_4,使用“goto”时,堆栈将是policy > chain new_in_4。)
上述并不是 nftables 独有的;iptables 中的情况大致相同(也有“JUMP”和“GOTO”、链策略和没有最终裁决的规则)。
\nnftables 可以让您逐个查看数据包处理规则 \xe2\x80\x93 将规则应用于nftrace set 1您的数据包(最好尽早)并运行nft monitor trace.
编写规则集的更易读的方法是:
\n#!/usr/bin/nft -f\n\ntable ip filter4 {\n chain input {\n type filter hook input priority filter; policy drop;\n ct state new goto new_in_4\n }\n\n chain new_in_4 {\n comment "New input IPv4 traffic"\n log prefix "some comment: "\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n通常与 \xe2\x80\x93 相反,chain new输入链将有一个规则来覆盖接受已建立的数据包,然后其他所有内容都将是“新的”,并且您根本不需要第二条链。
table ip filter4 {\n chain input {\n type filter hook input priority filter; policy drop;\n ct state established,related accept\n\n comment "New input IPv4 traffic"\n log prefix "some comment: "\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
330 次 |
| 最近记录: |