iptables规则的持久化方法是什么(iptables,开发技术)

时间:2024-05-03 17:21:19 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :
iptables规则的持久化方法是什么

iptables规则持久化

设定防火墙规则

iptables-AINPUT-s1.1.1.1/32-ptcp-mtcp--dport22-jDROPiptables-AINPUT-s2.2.2.2/32-ptcp-mtcp--dport22-jDROPiptables-AINPUT-s3.3.3.3/32-ptcp-mtcp--dport22-jDROPiptables-AINPUT-s4.4.4.4/32-ptcp-mtcp--dport22-jDROP

保存防火墙规则

iptables-save>/etc/sysconfig/iptables

设定开机自动恢复iptables规则

vim/etc/rc.d/rc.localiptables-restore

iptables关机自动保存

先清空防火墙规则

iptables-F

保存iptables规则,也就是说将/etc/sysconfig/iptables文件清空

iptables-save>/etc/sysconfig/iptables

手动生成一些iptables规则

iptables-AINPUT-s1.1.1.1/32-ptcp-mtcp--dport22-jDROPiptables-AINPUT-s2.2.2.2/32-ptcp-mtcp--dport22-jDROPiptables-AINPUT-s3.3.3.3/32-ptcp-mtcp--dport22-jDROPiptables-AINPUT-s4.4.4.4/32-ptcp-mtcp--dport22-jDROP

查看iptables规则是否生效

[root@ecs-7740init.d]#iptables-nvLChainINPUT(policyACCEPT27packets,1978bytes)pktsbytestargetprotoptinoutsourcedestination00DROPtcp--**1.1.1.10.0.0.0/0tcpdpt:2200DROPtcp--**2.2.2.20.0.0.0/0tcpdpt:2200DROPtcp--**3.3.3.30.0.0.0/0tcpdpt:2200DROPtcp--**4.4.4.40.0.0.0/0tcpdpt:22

设定关机时自动保存iptables规则 创建关机时要执行的脚本,并且确保其有执行权限

vim/etc/init.d/shutdownshiptables-save>/etc/sysconfig/iptableschmod+x/etc/sysconfig/shutdownshls/etc/sysconfig/shutdownsh-rwxr-xr-x1rootroot40Jan1622:05shutdownsh

创建软连接文件至rcN.d路径下,N为运行等级

ln-s/etc/init.d/shutdownsh/etc/rc6.d/K01shutdownshln-s/etc/init.d/shutdownsh/etc/rc0.d/K01shutdownshln-s/etc/init.d/shutdownsh/var/lock/subsys/

注:以上方法(在/var/lock/subusys创建空文件或者软连接,仅在第一次关机或重启有效,当重启后/var/lock/subsys下的文件就自动消失了,所以在第二次关机或者重启脚本并不能执行)

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:iptables规则的持久化方法是什么的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:LAMP下如何搭建WordPress博客下一篇:

13 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18