[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

script iptables



Un amico mi ha passato il suo script che usa per lanciare e stoppare
iptables.
Utilizza una suse lui.
Io l'ho copiato in /etc/init.d con il nome iptables e mi sono creato il mio
file delle regole in /usr/local/bin con il nome di rc.firewall.
Quanto vado a lanciare ./iptables restart da /etc/init.d mi esce l'avviso
che iptables è stato prima stoppato e poi
è ripartito ma se lancio un iptables -L non vedo nessuna regola aggiunta.

I permessi dei due file (/etc/init.d/iptables e /usr/local/bin/rc.firewall)
attualmente li ho messi a 777 tanto per non avere problemi di questo tipo.
Secondo voi perchè non mi vengono caricate le regole? Dipende dallo script o
dal file delle regole?
Sotto trovate lo script e il file delle regole.

Ecco lo script (/etc/init.d/iptables)

#!/bin/bash
#
### BEGIN INIT INFO
# Provides:       SuSE
# Required-Start: $network $named $syslog
# Required-Stop:  $network
# Default-Start: 2 3 5
# Default-Stop:  0 1 6
# Description:    This script is loading the firewall
### END INIT INFO

# Carica il modulo per l'ftp dinamico

#/sbin/modprobe ip_nat_ftp

if [ -r /etc/rc.status ] ; then
   . /etc/rc.status
fi

if [ -r /etc/rc.config ] ; then
   . /etc/rc.config
fi

# Determine the base and follow a runlevel link name.
base=${0##*/}
link=${base#*[SK][0-9][0-9]}

return=$rc_done

IPTABLES=/usr/sbin/iptables
if [ ! -x $IPTABLES ] ; then
   echo "Can't find ${IPTABLES}"
   exit 1
fi

FIREWALLSCRIPT="/usr/local/bin/rc.firewall"
if [ ! -x ${FIREWALLSCRIPT} ] ; then
   echo "Can't find firewallscript ${FIREWALLSCRIPT}"
   exit 1
fi

LOGFILE=/var/log/firewall.log

case "$1" in
   start)
      echo -n "Starting Server firewall and NAT services:"
      ${FIREWALLSCRIPT} 1>${LOGFILE} 2>&1 || return=$rc_failed
      echo -e "$return"
      ;;
   stop)
      echo -n "Stop firewall and NAT services:"
      #################################################
      # Reset the default policies in the filter table.
      #################################################
      ${IPTABLES} --table filter --policy INPUT ACCEPT
      ${IPTABLES} --table filter --policy FORWARD ACCEPT
      ${IPTABLES} --table filter --policy OUTPUT ACCEPT

      #
      # reset the default policies in the nat table.
      # Everything allowed!!
      #
      ${IPTABLES} --table nat --policy PREROUTING ACCEPT
      ${IPTABLES} --table nat --policy POSTROUTING ACCEPT
      ${IPTABLES} --table nat --policy OUTPUT ACCEPT

      #
      # reset the default policies in the mangle table.
      #
      ${IPTABLES} --table mangle --policy PREROUTING ACCEPT
      ${IPTABLES} --table mangle --policy OUTPUT ACCEPT

      #
      # flush all the rules in the filter and nat tables.
      #
      ${IPTABLES} --table filter --flush
      ${IPTABLES} --table nat --flush
      ${IPTABLES} --table mangle --flush

      #
      # erase all chains that's not default in filter and nat table.
      #
      ${IPTABLES} --table filter --delete-chain
      ${IPTABLES} --table nat --delete-chain
      ${IPTABLES} --table mangle --delete-chain
      echo -e "$return"
      ;;
   status)
      echo "Status firewall and NAT services:"
      ${IPTABLES} -L
      ;;
   restart|reload)
      $0 stop  &&  $0 start  ||  return=$rc_failed
      ;;
   *)
      echo "Usage: $0 {start|stop|status|restart|reload}"
      exit 1
esac

# Inform the caller not only verbosely and set an exit status.
test "$return" = "$rc_done" || exit 1
exit 0


Ed ecco il file /usr/local/bin/rc.firewall

#!bin/sh
#
iptables -F
iptables -t nat -F
iptables -t mangle -F

iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT

Ho impostato queste regole semplici tanto per vedere se funziona il tutto.
poi devo personalizzarle.

ciao



Reply to: