您的位置:首页 > 运维架构 > Linux

centos7 编写防火墙增加和删除端口脚本

2017-10-23 10:27 387 查看
#!/bin/bash
num=$#
ok=0
if [ ${num} != 2 ]
then
echo 'error:you must input two parmas, first is add or remove, second is port number'
exit 0
fi

case $1 in
add)
status=$(firewall-cmd --zone=public --add-port=$2/tcp --permanent)
echo "add port status:${status}"
ok=1
;;

remove)
status=$(firewall-cmd --zone=public --remove-port=$2/tcp --permanent)
echo "remove port status:${status}"
ok=1
;;

*)
echo 'you must input two parmas, first is add or remove'
;;

esac

if [ ${ok} == 1 ]
then
status=`firewall-cmd --reload`
echo "reload firewall status:${status}"
ports=`firewall-cmd --list-ports`
echo "ports list:${ports}"
fi

exit 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: