Guest User

Untitled

a guest
Dec 12th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. #!/bin/bash
  2. echo Setting firewall rules...
  3. #
  4. #
  5.  
  6. ###### Debut Initialisation ######
  7.  
  8. # Interdire toute connexion entrante
  9. iptables -t filter -P INPUT DROP
  10. iptables -t filter -P FORWARD DROP
  11. echo - Interdire toute connexion entrante : [OK]
  12.  
  13. # Interdire toute connexion sortante
  14. iptables -t filter -P OUTPUT DROP
  15. echo - Interdire toute connexion sortante : [OK]
  16.  
  17. # Vider les tables actuelles
  18. iptables -t filter -F
  19. iptables -t filter -X
  20. echo - Vidage : [OK]
  21.  
  22. #Creation d'une chaine
  23. iptables -N LOG_REJECT_SMTP
  24. iptables -A LOG_REJECT_SMTP -j LOG --log-prefix ' SMTP REJECT PAQUET : '
  25. iptables -A LOG_REJECT_SMTP -j DROP
  26.  
  27. # Anti-Taiwanais
  28. iptables -t filter -A INPUT -i eth0 -s 61.64.128.0/17 -j LOG_REJECT_SMTP
  29. iptables -t filter -A INPUT -i eth0 -s 122.120.0.0/13 -j LOG_REJECT_SMTP
  30. iptables -t filter -A INPUT -i eth0 -s 168.95.0.0/16 -j LOG_REJECT_SMTP
  31. echo - Bloquer Taiwanais : [OK]
  32.  
  33. # Ne pas casser les connexions etablies
  34. iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  35. iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  36. echo - Ne pas casser les connexions établies : [OK]
  37.  
  38. # Autoriser la Supervision du serveur (SNMP)/ desactiver pour le moment
  39. #iptables -t filter -A INPUT -p tcp --dport 161 -s IP_SUPERVISION/32 -j ACCEPT
  40. #iptables -t filter -A INPUT -p udp --dport 161 -s IP_SUPERVISION/32 -j ACCEPT
  41. #echo - Autoriser Supervision : [OK]
  42.  
  43. # Autoriser les requetes DNS, FTP (passif et actif), HTTP, NTP
  44. iptables -t filter -A OUTPUT -p tcp --dport 21 -j ACCEPT
  45. iptables -t filter -A OUTPUT -p tcp --dport 80 -j ACCEPT
  46. iptables -t filter -A OUTPUT -p tcp --dport 53 -j ACCEPT
  47. iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT
  48. iptables -t filter -A OUTPUT -p udp --dport 123 -j ACCEPT
  49. echo - Autoriser les requetes DNS, FTP, HTTP : [OK]
  50.  
  51. # Autoriser loopback
  52. iptables -t filter -A INPUT -i lo -j ACCEPT
  53. iptables -t filter -A OUTPUT -o lo -j ACCEPT
  54. echo - Autoriser loopback : [OK]
  55.  
  56. # Autoriser ping
  57. iptables -t filter -A INPUT -p icmp -j ACCEPT
  58. iptables -t filter -A OUTPUT -p icmp -j ACCEPT
  59. echo - Autoriser ping : [OK]
  60.  
  61. # HTTP
  62. iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
  63. iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT
  64. echo - Autoriser serveur Apache : [OK]
  65.  
  66. modprobe ip_conntrack_ftp
  67. iptables -t filter -A INPUT -p tcp --dport 21 -j ACCEPT
  68. iptables -t filter -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  69. echo - Autoriser serveur FTP : [OK]
  70.  
  71. #DNS
  72. iptables -t filter -A INPUT -p tcp --dport 53 -j ACCEPT
  73. iptables -t filter -A INPUT -p udp --dport 53 -j ACCEPT
  74. echo - Autoriser serveur Bind : [OK]
  75.  
  76. # Mail
  77. iptables -t filter -A INPUT -p tcp --dport 25 -j ACCEPT
  78. iptables -t filter -A INPUT -p tcp --dport 110 -j ACCEPT
  79. iptables -t filter -A INPUT -p tcp --dport 143 -j ACCEPT
  80. iptables -t filter -A OUTPUT -p tcp --dport 25 -j ACCEPT
  81. iptables -t filter -A OUTPUT -p tcp --dport 110 -j ACCEPT
  82. iptables -t filter -A OUTPUT -p tcp --dport 143 -j ACCEPT
  83. echo - Autoriser serveur Mail : [OK]
  84.  
  85. # Autoriser SSH
  86. iptables -t filter -A INPUT -p tcp --dport 6060 -m recent --rcheck --seconds 60 --hitcount 2 --name SSH -j LOG --log-prefix "SSH REJECT"
  87. iptables -t filter -A INPUT -p tcp --dport 6060 -m recent --update --seconds 60 --hitcount 2 --name SSH -j DROP
  88. iptables -t filter -A INPUT -p tcp --dport 6060 -m state --state NEW -m recent --set --name SSH -j ACCEPT
  89.  
  90. # Autoriser Webmin
  91. iptables -t filter -A INPUT -p tcp -m tcp --dport 10000 -j ACCEPT
  92. echo - Autoriser Webmin : [OK]
Add Comment
Please, Sign In to add comment