Advertisement
Guest User

Untitled

a guest
Aug 30th, 2012
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.62 KB | None | 0 0
  1. #!/bin/bash
  2. # ---------------------------------------------------------------------
  3. # Linux-iptables-Firewallskript, Copyright (c) 2010 under the GPL
  4. # Autogenerated by iptables Generator v1.22 (c) 2002-2010 by Harald Bertram
  5. # Please visit http://harry.homelinux.org for new versions of
  6. # the iptables Generator (c).
  7. #
  8. #
  9. # If you have questions about the iptables Generator or about
  10. # your Firewall-Skript feel free to take a look at out website or
  11. # send me an E-Mail to webmaster@harry.homelinux.org.
  12. #
  13. # My special thanks are going to Lutz Heinrich (trinitywork at hotmail dot com)
  14. # who made lots of Beta-Testing and gave me lots of well qualified
  15. # Feedback that made me able to improve the iptables Generator.
  16. # --------------------------------------------------------------------
  17. # Besondere Hinweise fuer Nutzer einer Debian-Distribution oder eines Debian-Derivates (Ubuntu, Knoppix, Kanotix, ...)!
  18. # Fuehren Sie die folgenden Kommandos aus, nachdem das Skript  "firewall" nach /etc/init.d kopiert wurde:
  19. # chmod 755 /etc/init.d/firewall
  20. # update-rc.d firewall defaults
  21. # /etc/init.d/firewall start
  22. # --------------------------------------------------------------------
  23.  
  24. case "$1" in
  25.  start)
  26.  echo "Starte IP-Paketfilter"
  27.  
  28.  # iptables-Modul
  29.  modprobe ip_tables
  30.  # Connection-Tracking-Module
  31.  modprobe ip_conntrack
  32.  # Das Modul ip_conntrack_irc ist erst bei Kerneln >= 2.4.19 verfuegbar
  33.  modprobe ip_conntrack_irc
  34.  modprobe ip_conntrack_ftp
  35.  
  36.  # Tabelle flushen
  37.  iptables -F
  38.  iptables -t nat -F
  39.  iptables -t mangle -F
  40.  iptables -X
  41.  iptables -t nat -X
  42.  iptables -t mangle -X
  43.  
  44.  # Default-Policies setzen
  45.  iptables -P INPUT DROP
  46.  iptables -P OUTPUT DROP
  47.  iptables -P FORWARD DROP
  48.  
  49.  # MY_REJECT-Chain
  50.  iptables -N MY_REJECT
  51.  
  52.  # MY_REJECT fuellen
  53.  iptables -A MY_REJECT -p tcp -j REJECT --reject-with tcp-reset
  54.  iptables -A MY_REJECT -p udp -j REJECT --reject-with icmp-port-unreachable
  55.  iptables -A MY_REJECT -p icmp -j DROP
  56.  iptables -A MY_REJECT -j REJECT --reject-with icmp-proto-unreachable
  57.  
  58.  # MY_DROP-Chain
  59.  iptables -N MY_DROP
  60.  iptables -A MY_DROP -j DROP
  61.  
  62.  # Reject packets from RFC1918 class networks (i.e., spoofed)
  63.  iptables -A INPUT -s 10.0.0.0/8     -j DROP
  64.  iptables -A INPUT -s 169.254.0.0/16 -j DROP
  65.  iptables -A INPUT -s 172.16.0.0/12  -j DROP
  66.  iptables -A INPUT -s 127.0.0.0/8    -j DROP
  67.  iptables -A INPUT -s 224.0.0.0/4      -j DROP
  68.  iptables -A INPUT -d 224.0.0.0/4      -j DROP
  69.  iptables -A INPUT -s 240.0.0.0/5      -j DROP
  70.  iptables -A INPUT -d 240.0.0.0/5      -j DROP
  71.  iptables -A INPUT -s 0.0.0.0/8        -j DROP
  72.  iptables -A INPUT -d 0.0.0.0/8        -j DROP
  73.  iptables -A INPUT -d 239.255.255.0/24 -j DROP
  74.  iptables -A INPUT -d 255.255.255.255  -j DROP
  75.  
  76.  
  77.  # Korrupte Pakete zurueckweisen
  78.  iptables -A INPUT -m state --state INVALID -j DROP
  79.  iptables -A OUTPUT -m state --state INVALID -j DROP
  80.  
  81.  # Stealth Scans etc. DROPpen
  82.  # Keine Flags gesetzt
  83.  iptables -A INPUT -p tcp --tcp-flags ALL NONE -j MY_DROP
  84.  
  85.  # SYN und FIN gesetzt
  86.  iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j MY_DROP
  87.  
  88.  # SYN und RST gleichzeitig gesetzt
  89.  iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j MY_DROP
  90.  
  91.  # FIN und RST gleichzeitig gesetzt
  92.  iptables -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j MY_DROP
  93.  
  94.  # FIN ohne ACK
  95.  iptables -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j MY_DROP
  96.  
  97.  # PSH ohne ACK
  98.  iptables -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j MY_DROP
  99.  
  100.  # URG ohne ACK
  101.  iptables -A INPUT -p tcp --tcp-flags ACK,URG URG -j MY_DROP
  102.  
  103.  # Loopback-Netzwerk-Kommunikation zulassen
  104.  iptables -A INPUT -i lo -j ACCEPT
  105.  iptables -A OUTPUT -o lo -j ACCEPT
  106.  
  107.  # Connection-Tracking aktivieren
  108.  iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
  109.  iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  110.  
  111.  # DNS
  112.  iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 53 -j ACCEPT
  113.  iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 53 -j ACCEPT
  114.  
  115.  # FTP
  116.  iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 21 -j ACCEPT
  117.  
  118.  # SSH
  119.  iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 22 -j ACCEPT
  120.  
  121.  # SMTP
  122.  iptables -A OUTPUT -o eth0 -m state --state NEW -p tcp --dport 25 -j ACCEPT
  123.  
  124.  # Webmin
  125.  iptables -A INPUT -i eth0 -m tcp -p tcp --dport 10000 -j ACCEPT
  126.  
  127.  # Webserver
  128.  iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  129.  iptables -A INPUT -p tcp --dport 667 -j ACCEPT
  130.  iptables -A INPUT -p tcp --dport 9000 -j ACCEPT
  131.  
  132.  # Default-Policies mit REJECT
  133.  iptables -A INPUT -j MY_REJECT
  134.  iptables -A OUTPUT -j MY_REJECT
  135.  
  136.  # Max. 500/Sekunde (5/Jiffie) senden
  137.  echo 5 > /proc/sys/net/ipv4/icmp_ratelimit
  138.  
  139.  # Speicherallozierung und -timing for-De/-Fragmentierung
  140.  echo 262144 > /proc/sys/net/ipv4/ipfrag_high_thresh
  141.  echo 196608 > /proc/sys/net/ipv4/ipfrag_low_thresh
  142.  echo 30 > /proc/sys/net/ipv4/ipfrag_time
  143.  
  144.  # TCP-FIN-Timeout zum Schutz vor DoS-Attacken setzen
  145.  echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
  146.  
  147.  # Maximal 3 Antworten auf ein TCP-SYN
  148.  echo 3 > /proc/sys/net/ipv4/tcp_retries1
  149.  
  150.  # TCP-Pakete maximal 15x wiederholen
  151.  echo 15 > /proc/sys/net/ipv4/tcp_retries2
  152.  
  153.  ;;
  154.  
  155.  stop)
  156.  echo "Stoppe IP-Paketfilter"
  157.  # Tabelle flushen
  158.  iptables -F
  159.  iptables -t nat -F
  160.  iptables -t mangle -F
  161.  iptables -X
  162.  iptables -t nat -X
  163.  iptables -t mangle -X
  164.  # Default-Policies setzen
  165.  iptables -P INPUT ACCEPT
  166.  iptables -P OUTPUT ACCEPT
  167.  iptables -P FORWARD ACCEPT
  168.  ;;
  169.  
  170.  status)
  171.  echo "Tabelle filter"
  172.  iptables -L -vn
  173.  echo "Tabelle nat"
  174.  iptables -t nat -L -vn
  175.  echo "Tabelle mangle"
  176.  iptables -t mangle -L -vn
  177.  ;;
  178.  
  179.  *)
  180.  echo "Fehlerhafter Aufruf"
  181.  echo "Syntax: $0 {start|stop|status}"
  182.  exit 1
  183.  ;;
  184.  
  185. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement