firewall 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. modprobe ip_tables
  3. iptables -F INPUT
  4. iptables -F OUTPUT
  5. iptables -F FORWARD
  6. iptables -F -t filter
  7. iptables -F POSTROUTING -t nat
  8. iptables -F PREROUTING -t nat
  9. iptables -F OUTPUT -t nat
  10. iptables -F -t nat
  11. iptables -t nat -F
  12. iptables -t mangle -F
  13. iptables -X
  14. # Zerando contadores
  15. iptables -Z
  16. iptables -t nat -Z
  17. iptables -t mangle -Z
  18. iptables -P INPUT DROP
  19. iptables -P OUTPUT ACCEPT
  20. iptables -P FORWARD DROP
  21. iptables -A INPUT -i lo -d 127.0.0.1 -j ACCEPT
  22. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  23. iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
  24. i=/proc/sys/net/ipv4
  25. # Desabilita o trafego IP entre as placas de rede
  26. echo "0" > /proc/sys/net/ipv4/ip_forward
  27. # Protecao contra SYN flood
  28. echo "1" > $i/tcp_syncookies
  29. echo "1" > $i/icmp_echo_ignore_broadcasts
  30. # Protecao contra responses bogus
  31. echo "1" > $i/icmp_ignore_bogus_error_responses
  32. echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
  33. iptables -I INPUT 1 -m state --state INVALID -j LOG --log-level info --log-prefix "PKT INVALIDO - "
  34. iptables -I INPUT 2 -m state --state INVALID -j DROP
  35. iptables -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 5/m -j ACCEPT
  36. echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all