systemctl enable netfilter-persistent 和systemctl enable nftables

瓦工BIGGERBOX-20-1024

systemctl enable netfilter-persistent 和systemctl enable nftables 都会重启后执行保存的防火墙规则,以哪个为准

在Debian 12 中,防火墙通常是iptables (nf_tables) 这是基于新的 nftables 框架的实现,旨在取代旧的 iptables,这是 nftables 的一个兼容层,旨在帮助用户平滑迁移。 systemctl enable netfilter-persistent systemctl enable nftables 都会在系统重启后加载防火墙规则,但它们的行为稍有不同。

netfilter-persistent:

netfilter-persistent 是一个管理 iptables 配置的脚本服务。它会读取 /etc/iptables/rules.v4 /etc/iptables/rules.v6 的文件,并在系统启动时应用规则,它通常用于保存和恢复防火墙规则,确保规则在系统重启后持久。

请注意,当执行 netfilter-persistent save 后,规则会保存到 /etc/iptables/rules.v4 和 /etc/iptables/rules.v6 中。当你重新启动系统时,iptables-persistent 服务会自动加载之前保存的 iptables 规则并应用它们。

nftables 服务:

nftables 服务会直接加载 /etc/nftables.conf 配置文件中的规则。如果你启用了 nftables 服务,它会在系统启动时自动加载规则。

谁优先?

如果你同时启用了 netfilter-persistent 和 nftables,它们会都尝试加载规则,但通常情况下 netfilter-persistent 服务的行为优先。netfilter-persistent 会在系统启动时加载规则,并确保它们持久化。而 nftables 服务会加载/etc/nftables.conf的规则。

推荐做法:

如果混用nftables和iptables,就全部开启,但是要注意各规则间有没有冲突。启用 nftables要确保规则被正确保存到 /etc/nftables.conf。同时开启nftables服务

systemctl enable nftables
systemctl start nftables

启用netfilter-persistent 服务:

systemctl enable netfilter-persistent

这样,你的2套规则都会重启后都会同时启用。nft list ruleset 也能看到iptables的规则。

技术不断升级,请注意文章时效性。
本站文章,欢迎转发。转载请注明出处:https://www.bandwh.com/kxsw/1883.html

(0)

BandWh.com 折腾之路●一起折腾

上一篇 2024年11月7日 13:18
下一篇 2024年11月23日 11:10
瓦工BIGGERBOX-20-1024

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

请文明评论!