Red Hat Training
A Red Hat training course is available for RHEL 8
8.5. 使用 nftables 命令中的集合
nftables
框架原生支持集合。您可以使用一个集合,例如,规则匹配多个 IP 地址、端口号、接口或其他匹配标准。
8.5.1. 在 nftables 中使用匿名集合
匿名集合包含用逗号分开的值,如 { 22、80、443 }
,它们直接在规则中使用。您还可以将匿名集合用于 IP 地址以及任何其他匹配标准。
匿名集合的缺陷是,如果要更改集合,则需要替换规则。对于动态解决方案,使用命名集合,如 在 nftables 中使用命名集合 中所述。
前提条件
-
inet
系列中的example_chain
链和example_table
表存在。
流程
例如,要向
example_table
中的example_chain
添加一条规则,其允许传入流量到端口22
、80
和443
:# nft add rule inet example_table example_chain tcp dport { 22, 80, 443 } accept
可选: 在
example_table
中显示所有链及其规则:# nft list table inet example_table table inet example_table { chain example_chain { type filter hook input priority filter; policy accept; tcp dport { ssh, http, https } accept } }