Linux
nftables是Netfilter的子项目,旨在替代现存的{ip,ip6,arp,eb}_tables,自 Linux 内核 3.13 开始支持。
特点
- 和
iptables类似,nftables使用表来存储链,表包含规则链,规则链包含规则 - 比
iptables更新速度更快,内核更新更少
安装
apt install -y nftables使用
# 列出所有表
nft list tables
# 列出所有规则
nft list ruleset
# 列出filter表
nft list table filter
# 列出filter表input链
nft list chain filter input
# filter 表与规则操作
# 1. 创建 filter 表
nft add table filter
# 2. 创建 input 链(nftables 新建表为空,需显式创建挂载 hook 的链)
nft add chain filter input { type filter hook input priority 0 \; }
# 3. 添加规则
nft add rule filter input tcp dport 22 accept
# 4. 删除规则(nftables 不支持按规则内容直接删除,需先通过 -a 查看 handle 编号,再通过 handle 删除)
nft -a list chain filter input
nft delete rule filter input handle <handle_num>