#!/bin/bash # # Author: Daniel Pecka # # /etc/init.d/myFW # and its symbolic link # /usr/sbin/rcmyFW # ### BEGIN INIT INFO # Provides: myFW # Required-Start: $ALL # Required-Stop: $network # Default-Start: 3 5 # Default-Stop: 0 1 2 6 # Description: myFW provides a routing and firewall ### END INIT INFO myFW_script=/usr/sbin/myFW_script; start_fw() { $myFW_script; exit 0; }; stop_fw() { echo "clearing rules .."; iptables -F; iptables -t nat -F; iptables -X; iptables -P INPUT ACCEPT; iptables -P OUTPUT ACCEPT; iptables -P FORWARD ACCEPT; exit 0; }; status_fw() { iptables -L; echo; iptables -t nat -L; exit 0; }; ## if passed some parametr, it's definitely ran by user if [ ! -z $1 ]; then case $1 in start) start_fw;; stop) stop_fw;; status) status_fw;; *) echo "use one of start, stop or status"; exit=1;; esac; exit 0; fi ## if not, it's run by init, so: ## determines if we're in startmode (^S) or killmode (^K) mode=$(echo $0 | sed 's@^.*/\(.\).*$@\1@'); case $mode in S) start_fw;; K) stop_fw;; *) echo "use one of start, stop or status"; exit=1;; esac; ## weird-end echo "it should never print this .."; exit 99;