Initscript per firewall iptables su Debian

From RVM Wiki
Revision as of 14:04, 16 December 2005 by Gabriele.vivinetto (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Creazione initscript

cat > /etc/init.d/firewall <<'EOFile'
#!/bin/sh -e
#
# v1.0 2005.12.16
# gabriele.vivinetto@rvmgroup.it

test $DEBIAN_SCRIPT_DEBUG && set -v -x

DESC="firewall"
CONFIG_DIR=/etc/firewall
test -d $CONFIG_DIR || {
  echo $CONFIG_DIR missing, nothing to do.
  exit 1
}

start_firewall () {
  . $CONFIG_DIR/start.firewall || {
  echo $CONFIG_DIR/start.firewall missing, not starting $DESC
  exit 1
  }

stop_firewall () {
  . $CONFIG_DIR/start.firewall || {
  echo $CONFIG_DIR/stop.firewall missing, not stopping $DESC
  exit 1
  }

case "$1" in
start)
  echo -n "Starting $DESC:"
  start_firewall
  echo "."
  ;;

stop)
  echo -n "Stopping $DESC:"
  stop_firewall
  echo "."
  ;;

restart)
  shift
  $0 stop
  sleep 1
  $0 start
  ;;

*)
  echo "Usage: $0 {start|stop|restart}" >&2
  exit 1
  ;;
esac

exit 0

# vim:set ai sts=2 sw=2 tw=0:
EOFile

chmod 755 /etc/init.d/firewall
mkdir /etc/firewall

Creazione regole

Le regole sono contenute in due files:

  • /etc/firewall/start-firewall: contiene le regole necessarie alla partenza del firewall. Questo files sarà eseguito dando l'opzione start all'initscript.
  • /etc/firewall/stop-firewall: contiene le regole necessarie alla disattivazione di tutte le regole del firewall. Questo files sarà eseguito dando l'opzione stop all'initscript.

Se questi files non esistono, l'initscript terminerà.

Attivazione dell'initscript

Creaiamo i link di partena automatica dello script, che deve essere attivato dopo aver configurato le interfacce:

sudo update-rc.d firewall start 41 S . stop 89 0 6 .