iptables规则的持久化方法是什么
导读:本文共1373字符,通常情况下阅读需要5分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 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-jDROPipt... ...
音频解说
目录
(为您整理了一些要点),点击可以直达。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规则的持久化方法是什么的详细内容,希望对您有所帮助,信息来源于网络。