1.shell脚本关闭防火墙1
[ root@localhost ~]
STATUS= $( systemctl status firewalld | grep "Active:" | awk '{print $2 }' )
case "$1 " in
start)
if [ $STATUS = active ]
then
echo "防火墙处于开启状态,无需操作!"
else
echo "防火墙正在开启中..."
systemctl start firewalld & > /dev/null
echo "防火墙已经开启!"
fi
; ;
stop)
if [ $STATUS = inactive ]
then
echo "防火墙处于关闭状态,无需操作!"
else
echo "防火墙正在关闭中..."
systemctl stop firewalld & > /dev/null
echo "防火墙已关闭!"
fi
; ;
status)
if [ $STATUS = active ]
then
systemctl status firewalld & > /dev/null
echo "防火墙处于开启状态!"
else
systemctl status firewalld & > /dev/null
echo "防火墙处于关闭状态!"
fi
; ;
*)
echo "请输入正确格式:start/stop/status"
esac
[ root@localhost ~]
[ root@localhost ~]
防火墙正在开启中.. .
防火墙已经开启!
[ root@localhost ~]
防火墙处于开启状态!
[ root@localhost ~]
防火墙正在关闭中.. .
防火墙已关闭!
[ root@localhost ~]
防火墙处于关闭状态!
[ root@localhost ~]
请输入正确格式:start/stop/status
2. 关闭防火墙脚本2
[ root@localhost ~]
STATUS= $( systemctl status firewalld | grep "running" )
case "$1 " in
start)
if [ $? = 0 ]
then
echo "防火墙处于开启状态,无需操作!"
else
echo "防火墙正在开启中..."
systemctl start firewalld & > /dev/null
echo "防火墙已经开启!"
fi
; ;
stop)
if [ $? != 0 ]
then
echo "防火墙处于关闭状态,无需操作!"
else
echo "防火墙正在关闭中..."
systemctl stop firewalld & > /dev/null
echo "防火墙已关闭!"
fi
; ;
status)
if [ $? = 0 ]
then
systemctl status firewalld & > /dev/null
echo "防火墙处于开启状态!"
else
systemctl status firewalld & > /dev/null
echo "防火墙处于关闭状态!"
fi
; ;
*)
echo "请输入正确格式:start/stop/status"
esac
[ root@localhost ~]
[ root@localhost ~]
防火墙正在开启中.. .
防火墙已经开启!
[ root@localhost ~]
防火墙处于开启状态!
[ root@localhost ~]
防火墙正在关闭中.. .
防火墙已关闭!
[ root@localhost ~]
防火墙处于关闭状态!
[ root@localhost ~]
请输入正确格式:start/stop/status
3.关闭核心防护
[ root@localhost ~]
se_cnf= "/etc/selinux/config"
find_key= "SELINUX="
setenforce 0 & > /dev/null
sed -ri "/^$find_key /c${find_key} disabled" $se_cnf
result= "` getenforce` "
if [ $result = Enforing ] ; then
echo "selinux关闭失败!"
exit 10
else
echo "selinux关闭成功!"
fi
[ root@localhost ~]
[ root@localhost ~]
selinux关闭成功!
[ root@localhost ~]
setenforce: SELinux is disabled