首页 > 系统 > Linux > 正文

Shell实现的iptables管理脚本分享

2019-10-26 18:44:24
字体:
来源:转载
供稿:网友

以前的脚本是用save模式,现在把命令附加到一个文件里面,这样的话,可以方便的二次修改什么的
脚本基本是这样的,大家可以跟自己的情况再次修改~  增加功能什么的。

代码如下:
#!/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) 针对服务器端口放行添加"
          echo "(3) 针对有端口和服务的ACL添加(这里要参数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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表