jeffersoncp
(usa Debian)
Enviado em 18/10/2012 - 08:46h
olá pinguinianos
tenho um script que ta bloquiando o servidor e nao deixa pingar, navegar... ou seja eu errei alguma coisa e nao sei aonde ta
Ps: Servidor Asterisk neste script resolve DNS mas nao tem conexao pra fora SSH e ping interno OK
script >>>
#!/bin/bash
# Definindo Variaveis
IPTABLES=/sbin/iptables
#INT=eth1
INT=eth0
firewall_start() {
echo "==============================================="
echo "| :: SETANDO A CONFIGURACAO DO IPTABLES :: |"
echo "==============================================="
# Limpando as regras de firewall
$IPTABLES -F INPUT
$IPTABLES -F OUTPUT
$IPTABLES -F FORWARD
echo "Limpando todas as regras .................[ OK ]"
# Defininindo Politicas para as Chains
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD DROP
echo "Setando as regras padrao .................[ OK ]"
# Liberando INPUT para o nagios
$IPTABLES -A INPUT -s 172.16.0.253 -j ACCEPT
$IPTABLES -A INPUT -s 172.16.0.1 -j ACCEPT
# Setando proteçao contra ataques
# Descarte de pacotes nao-identificado ICMP (ping)
$IPTABLES -A OUTPUT -m state -p icmp --state INVALID -j DROP
# Contra DoS:
$IPTABLES -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
# Contra Port Scanners:
$IPTABLES -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
# Contra Pings da morte
$IPTABLES -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
# Bloquear Back Orifice:
$IPTABLES -A INPUT -p tcp --dport 31337 -j DROP
$IPTABLES -A INPUT -p udp --dport 31337 -j DROP
# Bloquear NetBus:
$IPTABLES -A INPUT -p tcp --dport 12345:12346 -j DROP
$IPTABLES -A INPUT -p udp --dport 12345:12346 -j DROP
for spoofing in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo "1" > $spoofing
done
echo "Setando a protecao anti-spoofing .........[ OK ]"
# Protecao contra responses bogus
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo "Setando anti-bogus_response ..............[ OK ]"
# Protecao contra ataques de syn flood (inicio da conexao TCP). Tenta conter ataques de DoS.
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo "Setando protecao anti_synflood ...........[ OK ]"
# Protecao contra port scanners ocultos
$IPTABLES -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
$IPTABLES -A INPUT -s 0.0.0.0/0 -p icmp -j DROP
#Protecoes contra ataques
$IPTABLES -A INPUT -m state --state INVALID -j DROP
$IPTABLES -A OUTPUT -p tcp ! --tcp-flags SYN,RST,ACK SYN -m state --state NEW -j DROP
#Ping da morte
$IPTABLES -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
#Protecao contra Syn-floods
$IPTABLES -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
# Liberando acesso para a interface loopback (Localhost)
$IPTABLES -A INPUT -i lo -j ACCEPT
# Liberando ssh
$IPTABLES -A INPUT -p tcp -d 172.16.0.251 --dport 22 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
# Tratando conexões estabelecidas e relacionadas (Esta é muito importante)
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
echo "Setando regras para INPUT ................[ OK ]"
# Libera Forward necessário
$IPTABLES -A FORWARD -i $INT -p udp --dport 53 -j ACCEPT
$IPTABLES -A FORWARD -p tcp --dport 22 -j ACCEPT
#Liberando DNS
$IPTABLES -A OUTPUT -p udp --dport 53 -j ACCEPT
#Liberando VoIP e Vono
$IPTABLES -A OUTPUT -p udp --dport 1571 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --dport 1571 -j ACCEPT
$IPTABLES -A OUTPUT -p udp --dport 5060 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --dport 5060 -j ACCEPT
$IPTABLES -A OUTPUT -p udp --dport 5061 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --dport 5061 -j ACCEPT
$IPTABLES -A OUTPUT -p udp --dport 5062 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --dport 5062 -j ACCEPT
$IPTABLES -A INPUT -p udp --dport 1571 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 1571 -j ACCEPT
$IPTABLES -A INPUT -p udp --dport 5060 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 5060 -j ACCEPT
$IPTABLES -A INPUT -p udp --dport 5061 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 5061 -j ACCEPT
$IPTABLES -A INPUT -p udp --dport 5062 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 5062 -j ACCEPT
#Bloqueia todo o resto
#iptables -A INPUT -p tcp -j LOG --log-level 6 --log-prefix "FIREWALL: GERAL "
$IPTABLES -A INPUT -p tcp --syn -j DROP
$IPTABLES -A INPUT -p tcp -j DROP
$IPTABLES -A INPUT -p udp -j DROP #Bloqueia todo o resto
#iptables -A INPUT -p tcp -j LOG --log-level 6 --log-prefix "FIREWALL: GERAL "
$IPTABLES -A INPUT -p tcp --syn -j DROP
$IPTABLES -A INPUT -p tcp -j DROP
$IPTABLES -A INPUT -p udp -j DROP
# Blacklist
$IPTABLES -I INPUT -s 201.21.167.23 -j DROP
$IPTABLES -I INPUT -s 84.16.234.85 -j DROP
$IPTABLES -I INPUT -s 203.169.184.38 -j DROP
$IPTABLES -I INPUT -s 38.108.111.100 -j DROP
$IPTABLES -I INPUT -s 203.93.106.46 -j DROP
$IPTABLES -I INPUT -s 184.106.169.97 -j DROP
$IPTABLES -I INPUT -s 208.76.54.157 -j DROP
$IPTABLES -I INPUT -s 91.142.84.194 -j DROP
$IPTABLES -I INPUT -s 91.220.62.36 -j DROP
$IPTABLES -I INPUT -s 184.106.97.24 -j DROP
$IPTABLES -I INPUT -s 184.106.111.203 -j DROP
#$IPTABLES -I INPUT -s -j DROP
echo "Firewall configurado com sucesso .........[ OK ]"
echo
}
firewall_restart() {
firewall_stop
firewall_start
}
firewall_stop() {
echo "==========================================="
echo "| :: DESLIGANDO FIREWALL :: |"
echo "==========================================="
# Limpa as regras
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
echo "Setando as regras padrao .................[ OK ]"
$IPTABLES -F INPUT
$IPTABLES -F OUTPUT
$IPTABLES -F FORWARD
echo "Limpando todas as regras .................[ OK ]"
}
case "$1" in
'start')
firewall_start
;;
'stop')
firewall_stop
;;
'restart')
firewall_restart
;;
*)
firewall_start
esac