什么是 nftables#
nftables 是 Linux 新一代防火墙框架,用于替代:
- iptables
- ip6tables
- ebtables
特点:
- 统一 IPv4 / IPv6
- 性能更高(内核层优化)
- 语法更现代
- 支持集合(sets)和映射(maps)
安装 nftables#
1
| apt update && apt install nftables
|
启动服务#
1
2
| systemctl enable nftables
systemctl start nftables
|
检查状态:
1
| systemctl status nftables
|
确认是否接管系统#
检查 nft 是否生效:
检查 iptables 是否仍在使用(关键)
如果你看到:
空规则 → 正常
有规则 → 可能仍在用 iptables
强制系统使用 nftables(重要)#
Debian 可能使用兼容层:
1
| update-alternatives --config iptables
|
选择:
同样操作:
1
| update-alternatives --config ip6tables
|
默认配置文件#
加载方式:
1
| nft -f /etc/nftables.conf
|