主頁 > 知識庫 > Shell實現(xiàn)的iptables管理腳本分享

Shell實現(xiàn)的iptables管理腳本分享

熱門標簽:杭州機器人外呼系統(tǒng) excel地址地圖標注 旅游地圖標注大全 東莞電銷機器人價格一覽表 佛山高德地圖標注中心 百度地圖的地圖標注 陜西電銷卡外呼系統(tǒng)怎么安裝 百度地圖標注圖標更換 地圖標注超出范圍怎么辦

以前的腳本是用save模式,現(xiàn)在把命令附加到一個文件里面,這樣的話,可以方便的二次修改什么的
腳本基本是這樣的,大家可以跟自己的情況再次修改~  增加功能什么的。

復(fù)制代碼 代碼如下:

#!/bin/bash
while true
do
clear
echo "----------------------menu----------------------"
echo "(1) service iptables restart"
echo "(2) iptables add"
echo "(3) iptables delete"
echo "(4) iptables stop"
echo "(5) iptables save(不推薦使用這種模式)"
echo "(6) iptables status"
echo "(7) iptables ACL list"
echo "(0) exit"
echo "會在當前的目錄下生成一個fw.sh文件"
echo "-------------------------------------------------"
echo -n "enter you chose[0-7]:"
read num
if [ ${num} -lt 0 -o ${num} -gt 7 ]
    then
      echo "this is not between 0-7"
else
   if [ "${num}" == "1" ]
      then
      service iptables restart
else
   if [ "${num}" == "2" ]
#######################################################
       then
          while [ "1" == "1" ]
          do
          clear
          echo "----------------------add ACL----------------------"
          echo "(1) 針對源IP放行添加"
          echo "(2) 針對服務(wù)器端口放行添加"
          echo "(3) 針對有端口和服務(wù)的ACL添加(這里要參數(shù)IP和端口 例如 0/0 80)"
          echo "(4) 自定義添加"
          echo "(5) 退回上一級"
          echo "-------------------------------------------------"
          echo -n "enter you chose[0-4]:"
          read aclnum
          if [ "${aclnum}" == "1" ]
             then
             read ip
             iptables -A INPUT -s ${ip} -p tcp --dport 22 -j ACCEPT
         echo "iptables -A INPUT -s ${ip} -p tcp --dport 22 -j ACCEPT" >>fw.sh
#            service iptables save
          elif [ "${aclnum}" == "2" ]
             then
             rad ip
             iptables -A INPUT -p tcp --dport ${IP}  -j ACCEPT
         echo "iptables -A INPUT -p tcp --dport ${IP}  -j ACCEPT" >>fw.sh
#            service iptables save
          elif [ "${aclnum}" == "3" ]
             then
             read ip port
             iptables -A INPUT -p tcp -s ${ip} --dport ${port} -j ACCEPT
             echo "iptables -A INPUT -p tcp -s ${ip} --dport ${port} -j ACCEPT" >>fw.sh
#            service iptables save
          elif [ "${aclnum}" == "4" ]
             then
             read addacl
             `${addacl}`
             service iptables save
          else
             break
          fi
          echo -n "是否想繼續(xù)添加: [y/n]:"
          read contine
          if [ "${contine}" == "n" -o "${contine}" == "N" ]
             then
             break
             fi
          done
#######################################################
else
   if [ "${num}" == "3" ]
          then
          while [ "1" == "1" ]
          do
          clear
          echo "---------------------delete ACL----------------------"
          echo "(1) 針對源ip刪除"
          echo "(2) 針對端口刪除"
          echo "(3) 針對有端口和服務(wù)的ACL刪除"
          echo "(4) 自定義刪除"
          echo "(5) 退回上一級"
          echo "-------------------------------------------------"
          echo -n "enter you chose[0-5]:"
          read aclnum
          if [ "${aclnum}" == "1" ]
             then
             read ip
             iptables -D INPUT -s ${ip} -p tcp --dport 22 -j ACCEPT
             echo "iptables -D INPUT -s ${ip} -p tcp --dport 22 -j ACCEPT" >>fw.sh
#            service iptables save
          elif [ "${aclnum}" == "2" ]
             then
             read port
             iptables -D INPUT -p tcp --dport ${port}  -j ACCEPT
             echo "iptables -D INPUT -p tcp --dport ${port}  -j ACCEPT" >>fw.sh
#            service iptables save
          elif [ "${aclnum}" == "3" ]
             then
             read ip port
             iptables -D INPUT -p tcp -s ${ip} --dport ${port} -j ACCEPT
         echo "iptables -D INPUT -p tcp -s ${ip} --dport ${port} -j ACCEPT" >>fw.sh
#            service iptables save
          elif [ "${aclnum}" == "4" ]
             then
             read deleteacl
             `${deleteacl}`
             service iptables save
          else
             break
          fi
          echo -n "是否想繼續(xù)添加: [y/n]:"
          read contine
          if [ "${contine}" == "n" -o "${contine}" == "N" ]
             then
             break
             fi
          done
###################################################################
else
   if [ "${num}" == "4" ]
       then
       echo -e "`service iptables stop` "
else
   if [ "${num}" == "5" ]
       then
       echo -e "`service iptables save`"
else
   if [ "${num}" == "6" ]
       then
       echo -e "`service iptables status`"
else
   if [ "${num}" == "7" ]
       then
         while [ "1" == "1" ]
       do
       clear
       echo "---------------------list ACL----------------------"
       echo "(1) 查看當前正在使用的規(guī)則集"
       echo "(2) 查看每個策略或每條規(guī)則、每條鏈的簡單流量統(tǒng)計"
       echo "(3) 查看NAT表"
       echo "(4) 自定義查看"
       echo "(5) 退回上一級"
       echo "-------------------------------------------------"
       echo -n "enter you chose[0-5]:"
       read aclnum
       if [ "${aclnum}" == "1" ]
          then
          iptables -L
       elif [ "${aclnum}" == "2" ]
          then
          iptables -L -n -v
       elif [ "${aclnum}" == "3" ]
          then
          iptables -L -t nat
       elif [ "${aclnum}" == "4" ]
          then
          read listacl
          `${listacl}`
       else
        break
         fi
       echo -n "是否想繼續(xù)添加: [y/n]:"
          read contine
          if [ "${contine}" == "n" -o "${contine}" == "N" ]
             then
             break
          fi
       done
################################################
else   
   exit
fi
  fi
    fi
     fi
      fi
       fi
        fi
         fi
echo -n "Do you contine [y/n]:"
read contine
if [ "${contine}" == "n" -o "${contine}" == "N" ]
   then
   exit
fi
done

您可能感興趣的文章:
  • Shell監(jiān)控iptables運行狀態(tài)
  • Shell腳本實現(xiàn)監(jiān)控iptables規(guī)則是否被修改
  • Shell腳本實現(xiàn)監(jiān)控iptables運行狀態(tài)
  • Shell腳本配合iptables屏蔽來自某個國家的IP訪問
  • CentOS 7 下使用 iptables

標簽:南充 隨州 朝陽 雅安 通遼 西藏 青島 延邊

巨人網(wǎng)絡(luò)通訊聲明:本文標題《Shell實現(xiàn)的iptables管理腳本分享》,本文關(guān)鍵詞  Shell,實現(xiàn),的,iptables,管理,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Shell實現(xiàn)的iptables管理腳本分享》相關(guān)的同類信息!
  • 本頁收集關(guān)于Shell實現(xiàn)的iptables管理腳本分享的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章