next up previous contents
Next: Hostname setzen (kx_hostname.sh): Up: Anhang Previous: Dynamische Firewall (kx_fw_dyn.sh):   Contents

NAT (kx_fw_nat.sh):

#!/bin/sh

# /etc/init.d/kx_fw_nat.sh

# Network Adress Translation wird aktiviert.

IPTABLES=/sbin/iptables

case "$1" in

 start)

  $IPTABLES -F -t nat

  if ! [ -e /tmp/fw_fertig.txt ];then /

    etc/init.d/kx_fw_dyn.sh start

  fi

  set $(cat /tmp/ipsub_intern.txt | tr "/" " ")

  IP_INT=$1

  SUB_INT=$2

  set $(echo $IP_INT | tr "." " ")

  IP_INT_LAST=$4

  IP_INT_LAST_P=`expr $4 + 1`

  IP_PARTNER=$1.$2.$3.$IP_INT_LAST_P

  if [ $IP_INT_LAST = 1 ]; then

    IP_PARTNER10=10.0.0.$IP_INT_LAST_P

    IP_INT10=10.0.0.$IP_INT_LAST

    SUB_INT10=255.255.255.0

  elif [ $IP_INT_LAST = 23 ]; then

    IP_PARTNER10=10.0.1.$IP_INT_LAST_P

    IP_INT10=10.0.1.$IP_INT_LAST

    SUB_INT10=255.255.255.0

  elif [ $IP_INT_LAST = 45 ]; then

    IP_PARTNER10=10.0.2.$IP_INT_LAST_P

    IP_INT10=10.0.2.$IP_INT_LAST

    SUB_INT10=255.255.255.0

  elif [ $IP_INT_LAST = 109 ]; then

    IP_PARTNER10=10.0.3.$IP_INT_LAST_P

    IP_INT10=10.0.3.$IP_INT_LAST

    SUB_INT10=255.255.255.0

  elif [ $IP_INT_LAST = 67 ]; then

    IP_PARTNER10=10.0.4.$IP_INT_LAST_P

    IP_INT10=10.0.4.$IP_INT_LAST

    SUB_INT10=255.255.255.0

  fi

  # Route für die NAT-Adressen vom Partnerrechner

  route add -host $IP_PARTNER10 gw $IP_PARTNER

  # NAT-Umsetzung Ziel-IP-Adresse für alle Pakete zum Partnerrechner

  $IPTABLES -d $IP_PARTNER -t nat -A PREROUTING -j DNAT -to-destination $IP_PARTNER10

  # NAT-Umsetzung für eingehende Pakete vom Partnerrechner

  $IPTABLES -s $IP_PARTNER10 -t nat -A POSTROUTING -j SNAT -to-source $IP_PARTNER

  #Schalte Spoof-Protection ein

  if [ -e /proc/sys/net/ipv4/conf/all/rp_filter ]; then

    echo -n "Schalte Anti-Spoofing-Konfiguration ein (rp_filter)..."

    for f in /proc/sys/net/ipv4/conf/*/rp_filter; do

     echo 1 > $f

    done

    echo " done."

  else

    echo "Konnte Anti-Spoofing nicht einschalten -> manuell einschalten bitte."

  fi

  ;;

stop)

  $IPTABLES -F -t nat

  echo "NAT ausgeschaltet"

  ;;

*)

  echo "Usage: kx_fw_nat.sh {start|stop}"

  exit 0

  ;;

esac


next up previous contents
Next: Hostname setzen (kx_hostname.sh): Up: Anhang Previous: Dynamische Firewall (kx_fw_dyn.sh):   Contents
clumsy 2005-07-21