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

来源:互联网 发布:js判断只能输入数字 编辑:程序博客网 时间:2024/06/11 08:29
#!/bin/bashnum=$#ok=0if [ ${num} != 2 ]then    echo 'error:you must input two parmas, first is add or remove, second is port number'    exit 0ficase $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';;esacif [ ${ok} == 1 ]then    status=`firewall-cmd --reload`    echo "reload firewall status:${status}"    ports=`firewall-cmd --list-ports`    echo "ports list:${ports}"fiexit 0

原创粉丝点击