CentOS 7.x 用shell增長、刪除端口

1、在/usr/local/sbin/下建立port文件,不要擴展名,並給權限  chom 777 porthtml

#!/bin/bash
num=$#
ok=0
if [ ${num} == 1 ]; then
	if [ $1 == 'list' ]; then
	    firewall-cmd --zone=public --list-ports
    		exit 0
	fi
fi

if [ ${num} != 2 ]; then
    echo 'error:you must input two parmas, first is add or remote, second is port number'
    exit 0
fi

case $1 in

add)
firewall-cmd --zone=public --add-port=$2/tcp --permanent
#firewall-cmd --zone=public --add-port=$2/udp --permanent
ok=1
;;

remove)
firewall-cmd --zone=public --remove-port=$2/tcp --permanent
#firewall-cmd --zone=public --remove-port=$2/udp --permanent
ok=1
;;

*)
echo 'first params must be "add" or "remove"' 
;;

esac
if [ ${ok} == 1 ]; then
firewall-cmd --reload
firewall-cmd --zone=public --list-all
fi
exit 0

  2、用法bash

  #port add 8080tcp

  #port remove 8080spa

  #port listhtm

相關文章
相關標籤/搜索