防火墙规则保存
命令:iptables -save
工具:iptables services
[root@localhost ~]# iptables-save > /opt/iptables.bak
#将文件保存并备份到opt目录下
#iptables.bak为自定义文件名
[root@localhost ~]# iptables-restore < /opt/iptables.bak
#将备份文件导入到规则中
将文件设置开机时启动防火墙配置规则
[root@localhost ~]# vim .bashrc
······
iptables-restore < /opt/iptables.bak
#将导入命令添加到最后一行
#开机是读取.bashrc文件,自动生效
[root@localhost ~]# vim /etc/profile
#此文件配置必须登录生效,生产环境中会有不登录的情况,所以不建议使用
将防火墙规则永久保存
[root@localhost ~]# vim /etc/rc.d/rc.local
······
iptables-restore < /opt/iptables.bak
#/etc/rc.d/rc.local是加载用户自定义服务的文件,优先运行
[root@localhost ~]# chmod +x /etc/rc.d/rc.local
#配置完必须将文件赋予执行权限
-
保存命令