Linux防火墙主要有iptables和firewalld两种管理工具,以下是它们的配置备份方法:
使用iptables-save
命令备份规则,对于IPv4规则,可执行sudo iptables-save > /etc/iptables/rules.v4
;对于IPv6规则,执行sudo ip6tables-save > /etc/iptables/rules.v6
。也可安装iptables-persistent
包,在安装过程中选择保存当前规则,系统会自动将规则保存到/etc/iptables/
目录下。
可以使用firewall-cmd --runtime-to-permanent
命令将当前运行时配置转换为永久配置并保存到/etc/firewalld/
目录下。还可以直接复制/etc/firewalld/
目录下的配置文件到其他位置进行备份,如sudo cp -r /etc/firewalld /path/to/backup/
。