linux防火墙开启与关闭脚本(ubuntu与centos)

发布时间:2019-10-14编辑:脚本学堂
分享二例linux防火墙开启与关闭脚本,适用于ubuntu与centos两种系统,有研究linux下iptables防火墙的朋友,不妨做个参考。

操作系统:ubuntu 11.10 / centos 6.3

1,防火墙关闭脚本 firewall_close.sh:
 

复制代码 代码示例:
#!/bin/bash
 
#centos begin
 
#check the firewall status
#/etc/init.d/iptables stutas
 
#Temporary closed firewall
#/etc/init.d/iptables stop
 
#Permanent closed firewall
#chkconfig iptables off
 
#centos end
 
#ubuntu begin
 
#check the firewall status
ufw status
 
#Temporary closed firewall
ufw disable
 
#ubuntu end
 
exit

2,防火墙打开脚本 firewall_open.sh:
 

复制代码 代码示例:

#!/bin/bash
 
#centos begin
 
#check the firewall status
#/etc/init.d/iptables stutas
 
#Temporary closed firewall
#/etc/init.d/iptables start
 
#Permanent closed firewall
#chkconfig iptables on
 
#centos end
 
#ubuntu begin
 
#check the firewall status
ufw status
 
#Temporary open firewall
ufw enable

#ubuntu end

exit