regist service for iptables in Debian

          Posted on 2013-09-06 21:58 H2O 閱讀(774) 評(píng)論(0)  編輯  收藏

          From

          http://www.o4v.net/blog/index.php/debian-iptables-script/

           

          由于Debian安裝iptables后默認(rèn)不是服務(wù)提示service iptables提示unrecognized service,需要添加腳本到/etc/init.d/,腳本如下(下載iptables):


          #!/bin/sh -e
          #
          ## BEGIN INIT INFO
          #
           Provides: iptables
          #
           Required-Start:
          #
           Required-Stop:
          #
           Default-Start: 2 3 4 5
          #
           Default-Stop: 0 1 6
          #
           Short-Description: start and stop iptables firewall
          #
           Description: Start, stop and save iptables firewall
          #
          ## END INIT INFO 

          PATH
          =¡±/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin¡± 

          IPTABLES
          =/sbin/iptables

          IPTABLES_SAVE
          =/sbin/iptables-save

          IPTABLES_RESTORE
          =/sbin/iptables-restore

          IPTABLES_CONFIG
          =/etc/iptables.conf

           

          -x $IPTABLES ] || exit 0

           . 
          /lib/lsb/init-functions


           case 
          "$1" in
           start)
              log_action_begin_msg 
          "Starting firewall"
                   type usplash_write 
          >/dev/null 2>/dev/null && usplash_write "TIMEOUT 120" || true
              
          if $IPTABLES_RESTORE < $IPTABLES_CONFIG ; then
                  log_action_end_msg $?
              
          else
                  log_action_end_msg $?
              fi
                   type usplash_write 
          >/dev/null 2>/dev/null && usplash_write "TIMEOUT 15" || true
              ;;

           stop)
              log_action_begin_msg 
          "Saving current firewall configuration"
              
          if $IPTABLES_SAVE > $IPTABLES_CONFIG ; then
                  log_action_end_msg $?
              
          else
                  log_action_end_msg $?
              fi
              log_action_begin_msg 
          "Flushing ALL firewall rules from chains!"
              
          if $IPTABLES -F ; then
                  log_action_end_msg $?
              
          else
                  log_action_end_msg $?
              fi
              log_action_begin_msg 
          "Deleting ALL firewall chains [Warning: ACCEPTING ALL PORT SERVICES!]"
              
          if $IPTABLES -X ; then
                  $IPTABLES 
          -P INPUT ACCEPT
                  $IPTABLES 
          -P FORWARD ACCEPT
                  $IPTABLES 
          -P OUTPUT ACCEPT
                  log_action_end_msg $?
              
          else
                  log_action_end_msg $?
              fi
              ;;

           save)
              log_action_begin_msg 
          "Saving current firewall configuration"
              
          if $IPTABLES_SAVE > $IPTABLES_CONFIG ; then
                  log_action_end_msg $?
              
          else
                  log_action_end_msg $?
              fi
              ;;

           force
          -reload|restart)
              log_action_begin_msg 
          "Reloading firewall configuration [Warning: POTENTIAL NETWORK INSECURITY DURING RELOAD]"
              $IPTABLES 
          -F
              $IPTABLES 
          -X
              
          if $IPTABLES_RESTORE < $IPTABLES_CONFIG ; then
                  log_action_end_msg $?
              
          else
                  log_action_end_msg $?
              fi
              ;;

           
          *)
              echo 
          "Usage: /etc/init.d/iptables {start|stop|save|restart|force-reload}"
              exit 
          1
              ;;
           esac

           exit 0


          說明:保存為/etc/init.d/iptables,然后chmod +x /etc/init.d/iptables 添加運(yùn)行權(quán)限。


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          posts - 0, comments - 21, trackbacks - 0, articles - 101

          Copyright © H2O

          主站蜘蛛池模板: 绥棱县| 类乌齐县| 永城市| 隆子县| 宜都市| 沙湾县| 砀山县| 泗洪县| 永城市| 拉萨市| 辛集市| 广丰县| 仙桃市| 曲靖市| 五大连池市| 龙里县| 宾川县| 英山县| 民县| 宁乡县| 盐边县| 桑植县| 汨罗市| 建阳市| 台东市| 渭南市| 郁南县| 缙云县| 新宾| 孟津县| 玉田县| 会东县| 中阳县| 成都市| 台南县| 安国市| 库伦旗| 衡阳县| 崇州市| 阜康市| 普兰店市|