Guest User

Firewall por Rafael Umbelino

a guest
Oct 28th, 2010
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.73 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Firewall criado por Tlaloc (Rafael Umbelino).
  4. # Qualquer um pode utilizar este firewall, modificar conforme suas intenções, estudar e
  5. # propor melhorias.
  6. # Caso encontre falhas ou queira fazer sugestões, mande um e-mail para:
  7. # rafael.umb at hotmail dot com dot br
  8. # VIVA O LINUX! - Porque de graça é mais gostoso
  9.  
  10. depend()
  11. {
  12.     after net.lo
  13.     after net.eth0
  14. }
  15. start()
  16. {
  17.     # -- FIREWALL
  18.  
  19.     # Estes comandos limpam qualquer configuração residual
  20.  
  21.     iptables -F
  22.     iptables -P INPUT ACCEPT
  23.     iptables -P OUTPUT ACCEPT
  24.     iptables -P FORWARD ACCEPT
  25.  
  26.     # Definindo padrões
  27.     # estes padrões definem que TODA conexão que não for tratada por regra alguma será
  28.     # descartada sem aviso
  29.  
  30.     iptables -P INPUT DROP
  31.     iptables -P OUTPUT DROP
  32.     iptables -P FORWARD DROP
  33.    
  34.     # Definindo regras internas
  35.     # estas regras abaixo permitem a conversação entre servidores dentro do host que rodar o
  36.     # firewall
  37.    
  38.     iptables -I INPUT -i lo -j ACCEPT
  39.     iptables -I OUTPUT -o lo -j ACCEPT
  40.  
  41.     # Definindo regras de entrada
  42.     # regra 1: conexões de entrada, protocolo TCP, estabelecidas ou relacionadas, estão OK
  43.     # regra 2: respostas de pings que eu solicitar estão OK
  44.     # regra 3: respostas de "tempo excedido" para pings que eu solicitar estão OK
  45.     # regra 4: respostas de "destino inacessível" que eu solicitar estão OK
  46.     # regra 5: conexões de entrada, protocolo UDP, estabelecidas ou relacionadas, estão OK
  47.    
  48.     iptables -I INPUT -p tcp -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  49.     iptables -I INPUT -i eth0 -p icmp --icmp-type echo-reply -j ACCEPT
  50.     iptables -I INPUT -i eth0 -p icmp --icmp-type time-exceeded -j ACCEPT
  51.     iptables -I INPUT -i eth0 -p icmp --icmp-type destination-unreachable -j ACCEPT
  52.     iptables -I INPUT -p udp -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  53.    
  54.     # Definindo regras de saída
  55.     # Tem uma regra de saída do protocolo TCP para HTTP, HTTP seguro, SMTP, SMTP com SSL
  56.     # POP, POP com SSL e portas do MSN. Há uma regra em branco, basta preencher se quiser
  57.     # liberar algo além do que já está liberado.
  58.     # Se quiser bloquear alguma coisa que não use, basta comentar ou remover a linha.
  59.    
  60.     iptables -I OUTPUT -p tcp -o eth0 --dport 80 -j ACCEPT              # HTTP
  61.     iptables -I OUTPUT -p tcp -o eth0 --dport 443 -j ACCEPT             # HTTPS
  62.     iptables -I OUTPUT -p tcp -o eth0 --dport 25 -j ACCEPT              # SMTP
  63.     iptables -I OUTPUT -p tcp -o eth0 --dport 465 -j ACCEPT             # SMTPS
  64.     iptables -I OUTPUT -p tcp -o eth0 --dport 110 -j ACCEPT             # POP
  65.     iptables -I OUTPUT -p tcp -o eth0 --dport 965 -j ACCEPT             # POPS
  66.     iptables -I OUTPUT -p tcp -o eth0 --dport 6891:6901 -j ACCEPT           # MSN
  67.     iptables -I OUTPUT -p tcp -o eth0 --dport 1863 -j ACCEPT            # MSN
  68.     iptables -I OUTPUT -p tcp -o eth0 --dport 5190 -j ACCEPT            # MSN
  69.     iptables -I OUTPUT -p udp -o eth0 --dport 6891:6901 -j ACCEPT           # MSN
  70.     iptables -I OUTPUT -p udp -o eth0 --dport 1863 -j ACCEPT            # MSN
  71.     iptables -I OUTPUT -p udp -o eth0 --dport 5190 -j ACCEPT            # MSN
  72.     iptables -I OUTPUT -p icmp -o eth0 -m state --state NEW,ESTABLISHED -j ACCEPT   # ping para fora
  73.     # iptables -I OUTPUT -p (tcp/udp) -o eth0 --dport (portaInício:portaFim/porta) -j ACCEPT
  74.    
  75.     # Definindo regras do DNS
  76.     # altere o DNS informado para o que você utiliza
  77.    
  78.     iptables -I OUTPUT -p tcp -o eth0 --dport 53 -d 8.8.8.8 -j ACCEPT
  79.     iptables -I OUTPUT -p tcp -o eth0 --dport 53 -d 8.8.4.4 -j ACCEPT
  80.     iptables -I OUTPUT -p udp -o eth0 --dport 53 -d 8.8.8.8 -j ACCEPT
  81.     iptables -I OUTPUT -p udp -o eth0 --dport 53 -d 8.8.4.4 -j ACCEPT
  82.    
  83.     # Definindo demais regras
  84.     # Defina aqui outras regras que você possa querer, como regras de tratamento de pacotes.
  85. }
  86.  
  87. stop()
  88. {
  89.     iptables -F
  90.     iptables -P INPUT ACCEPT
  91.     iptables -P OUTPUT ACCEPT
  92.     iptables -P FORWARD ACCEPT
  93. }
  94.  
  95. reload()
  96. {
  97.     stop
  98.     start
  99. }
Advertisement
Add Comment
Please, Sign In to add comment