本文于 2025-01-21 09:27 更新,部分内容具有时效性,如有失效,请留言
#!/bin/bash
#----------------------------------------------------------------
# Powered by blog.ct99.cn
#
# File Name:moni.iptables.sh
# Description:Manager iptables
# author:Guilin Chen
# Date:2018-08-16
#
# Create identity:New
# Modifying identities:v1.0
# Modify Description:
#---------------------Http://blog.ct99.cn------------------------
if [ $# -eq 0 ];then
echo "需要传入参数!!!"
exit
fi
if [ $# -gt 1 ];then
echo "只需要一个参数即可,我就取前一个,后面的扔垃圾桶了。"
fi
Str=$1
Parameters=("stop" "start" "restart" "status")
Nulls="/dev/null"
ParsCount=${#Parameters[*]}
ParEn=0
for ((i=0;i<$ParsCount;i++))
do
Pars=${Parameters[$i]}
if [ $Str == $Pars ];then
ParEn=1
fi
done
if [ $ParEn -eq 0 ];then
echo "参数不合法,仅允许传入:stop, start, restart, status"
exit
fi
if [ $Str == "stop" ];then
echo "停用防火墙:"
/etc/init.d/iptables stop
elif [ $Str == "start" ];then
echo "启动防火墙:"
/etc/init.d/iptables start
elif [ $Str == "restart" ];then
echo "重启防火墙:"
/etc/init.d/iptables restart
else
echo "获取防火墙状态:"
/etc/init.d/iptables status
fi