由三个主要组件组成:内核实现、libnl netlink通信和nftables用户空间前端。 内核提供了一个netlink配置接口以及运行时规则集评估,libnl包含了与内核通信的基本函数,nftables前端是用户通过nft交互。
nftables 区分 命令行输入的临时规则 和 从文件加载或保存到文件的永久规则。
默认配置文件是/etc/nftables.conf,其中已经包含一个名为inet filter的简单ipv4/ipv6防火墙列表
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority filter;
}
chain forward {
type filter hook forward priority filter;
}
chain output {
type filter hook output priority filter;
}
}
默认是关闭的
systemctl status nftables
○ nftables.service - nftables
Loaded: loaded (/lib/systemd/system/nftables.service; disabled; preset: enabled)
Active: inactive (dead)
启用它
systemctl enable nftables
systemctl start nftables
iptables的缺点
iptables框架在内核态知道的太多,以至于产生了大量的代码冗余。 iptables的rule结构设计不合理。
检查 命令行 规则集
nft list ruleset
列出所有的表
nft list tables