Advertisement
todobom

Firewall Simples

Sep 4th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.59 KB | None | 0 0
  1. #!/bin/sh -e
  2. ### BEGIN INIT INFO
  3. # Provides:          firewall
  4. # Required-Start:    networking
  5. # Required-Stop:    
  6. # Default-Start:     S
  7. # Default-Stop:      0 6
  8. # Short-Description: Sets up the firewall
  9. # Description:       Sets up the firewall
  10. ### END INIT INFO
  11.  
  12. IPTABLES=/sbin/iptables
  13.  
  14. #
  15. # Reset everything
  16. #
  17.  
  18. $IPTABLES -F INPUT
  19. $IPTABLES -F OUTPUT
  20. $IPTABLES -F FORWARD
  21.  
  22.  
  23. #############################################################
  24. ###        INPUT RULES: Block almost everything           ###
  25. #############################################################
  26.  
  27. $IPTABLES -P INPUT DROP
  28.  
  29.  
  30. #
  31. # localhost and localnetwork connections
  32. #
  33. $IPTABLES -A INPUT -s 127.0.0.1/32       -j ACCEPT
  34.  
  35. #
  36. #
  37. # ICMP packets
  38. #
  39. $IPTABLES -A INPUT -p icmp --icmp-type echo-reply                -j ACCEPT
  40. $IPTABLES -A INPUT -p icmp --icmp-type echo-request              -j ACCEPT
  41. $IPTABLES -A INPUT -p icmp --icmp-type destination-unreachable   -j ACCEPT
  42. $IPTABLES -A INPUT -p icmp --icmp-type time-exceeded             -j ACCEPT
  43.  
  44. #
  45. # Established outgoing TCP connections
  46. #
  47. $IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  48.  
  49.  
  50. ## ssh - 3 conections per 10 minutes
  51. $IPTABLES -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 600 --hitcount 3 --name SSH -j DROP
  52. $IPTABLES -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH
  53.  
  54. #
  55. # incoming connections through TCP
  56. #
  57. $IPTABLES -A INPUT -p tcp --dport auth     -j REJECT
  58. $IPTABLES -A INPUT -p tcp --dport ssh      -j ACCEPT
  59. $IPTABLES -A INPUT -p tcp --dport ftp      -j ACCEPT
  60. $IPTABLES -A INPUT -p tcp --dport ftp-data -j ACCEPT
  61. $IPTABLES -A INPUT -p tcp --dport www      -j ACCEPT
  62. $IPTABLES -A INPUT -p tcp --dport smtp     -j ACCEPT
  63. $IPTABLES -A INPUT -p tcp --dport submission -j ACCEPT
  64. $IPTABLES -A INPUT -p tcp --dport imap2    -j ACCEPT
  65. $IPTABLES -A INPUT -p tcp --dport pop-3    -j ACCEPT
  66. $IPTABLES -A INPUT -p tcp --dport snmp     -j ACCEPT
  67. $IPTABLES -A INPUT -p tcp --dport domain   -j ACCEPT
  68.  
  69. #
  70. # incoming UDP packets
  71. #
  72.  
  73. $IPTABLES -A INPUT -p udp --dport domain   -j ACCEPT
  74. $IPTABLES -A INPUT -p udp --dport snmp     -j ACCEPT
  75.  
  76.  
  77. #############################################################
  78. ###          FORWARD RULES: Accept everything             ###
  79. #############################################################
  80.  
  81. $IPTABLES -P FORWARD ACCEPT
  82.  
  83.  
  84. #############################################################
  85. ###           OUTPUT RULES: Accept everything             ###
  86. #############################################################
  87.  
  88. $IPTABLES -P OUTPUT ACCEPT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement