WilhelmStein
(usa CentOS)
Enviado em 09/03/2011 - 15:08h
Pessoal, já procurei por todo site, já busquei ajuda de amigos administradores de rede, mas não consigo resolver o problema do meu script iptables. O problema é quando coloco as politicas como drop! Eu libero portas de serviços e tudo mais, mas mesmo assim a minha rede e o servidor local, mesmo com as portas e serviços liberados ficam sem conexão. O script é o seguinte:
#!/bin/bash
#criado por Guilherme Steinmüller
MOD="/sbin/modprobe"
#interface ligada a internet
SHARE_IF="eth0"
# Porta do Squid
PPort=3128
#rede interna
redeINT=192.168.50.0/24
################################
# INICIALIZANDO #
################################
# Limpar regras existentes
echo " "
echo "---->FASE 1<----"
echo " "
echo "Limpando regras..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
echo "Definindo políticas padrão..."
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
# Modulos do kernel
echo "Carregando os modulos do kernel..."
$MOD ip_tables
$MOD iptable_filter
$MOD iptable_nat
$MOD ip_conntrack
$MOD ipt_MASQUERADE
$MOD ip_nat_ftp
$MOD ip_nat_irc
$MOD ip_conntrack_ftp
$MOD ip_conntrack_irc
$MOD ipt_limit
$MOD ipt_state
$MOD ipt_REJECT
echo "Fase 1 concluída!"
echo " "
echo " "
echo " "
###################################################
# ROTEANDO INTERFACE E REDIRECIONANDO PACOTES #
###################################################
echo " "
echo "---->FASE 2<----"
echo " "
echo "Roteando interface eth0..."
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo "redirecionamento da porta 80 para SQUID"
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port $PPort
echo "Fase 2 concluída!"
echo " "
echo " "
echo " "
##############################################
# DEFININDO REGRAS DE ACESSO AO SERVIDOR #
#############################################
echo " "
echo "---->FASE 3<----"
echo " "
echo "Difinindo regras de acesso ao servidor"
# ilimitando o trafico via loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
echo "liberando portas..."
#liberando acesso da rede interna ao servidor
iptables -A INPUT -i eth1 -s $redeINT -d 192.168.50.1 -j ACCEPT
iptables -A INPUT -i eth1 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT #<----------------------------TESTE
#liberando portas no servidor
iptables -A INPUT -i eth1 -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -i eth1 -p tcp --dport 25 -j ACCEPT #Porta SMTP
iptables -A INPUT -i eth1 -p tcp --dport 53 -j ACCEPT #Porta DNS
iptables -A INPUT -i eth1 -p udp --dport 53 -j ACCEPT
iptables -A INPUT -i eth1 -p tcp --dport 110 -j ACCEPT #Porta POP3
iptables -A INPUT -i eth1 -p tcp --dport 135 -j ACCEPT #Porta RPC
iptables -A INPUT -i eth1 -p udp --dport 135 -j ACCEPT
iptables -A INPUT -i eth1 -p tcp --dport 139 -j ACCEPT #Porta COMPARTILHAMENTO
iptables -A INPUT -i eth1 -p udp --dport 139 -j ACCEPT
iptables -A INPUT -i eth1 -p tcp --dport 443 -j ACCEPT #Porta HTTPS
iptables -A INPUT -i eth1 -p tcp --dport 445 -j ACCEPT #Porta SAMBA
iptables -A INPUT -i eth1 -p udp --dport 445 -j ACCEPT
echo "Fase 3 concluída!"
echo " "
echo " "
echo " "
#################################
# POLÍTICAS DE ACESSO DA REDE #
#################################
echo " "
echo "---->FASE 4<----"
echo " "
echo "Liberar Pacotes de Retorno da Internet"
iptables -A INPUT -i eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
echo "Liberando portas de servicos"
iptables -A INPUT -i eth1 -s $redeINT -d 192.168.50.1 -p tcp --dport $PPort -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 25 -j ACCEPT #Porta SMTP
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 53 -j ACCEPT #Porta DNS
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 53 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 110 -j ACCEPT #Porta POP3
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 135 -j ACCEPT #Porta RPC
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 135 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 139 -j ACCEPT #Porta COMPARTILHAMENTO
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 139 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 443 -j ACCEPT #Porta HTTPS
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 445 -j ACCEPT #Porta SAMBA
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 445 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 1049 -j ACCEPT #Porta Necessária para envio de dados para SEFAZ
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 1049 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 1276 -j ACCEPT #Porta Necessária CONECTIVIDADE SOCIAL
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 1276 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 1723 -j ACCEPT #Porta Necessária CONECTIVIDADE SOCIAL
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 1723 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 2631 -j ACCEPT #Porta Necessária CONECTIVIDADE SOCIAL
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 2631 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 3456 -j ACCEPT #Porta Necessária RECEITANET
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 3456 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 5000 -j ACCEPT #Porta VPN
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 5000 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 5017 -j ACCEPT #Porta CAT - Cadastramento de Acidentes de Trabalho
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 5017 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 5592 -j ACCEPT #Porta CAT - Cadastramento de Acidentes de Trabalho
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 5592 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 8080 -j ACCEPT #SEFAZ
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 8080 -j ACCEPT
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 8081 -j ACCEPT #CEMAT (SERVICOS ONLINE)
iptables -A FORWARD -i eth1 -s $redeINT -p udp --dport 8081 -j ACCEPT
echo "bloqueios do msn e orkut "
#iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 443 -d orkut.com.br -j DROP
#iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 443 -d meebo.com -j DROP
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 1863 -j DROP
iptables -A FORWARD -i eth1 -s $redeINT -p tcp --dport 7001 -j DROP
iptables -t nat -A PREROUTING -i eth1 -s $redeINT -p tcp --dport 1863 -j DROP
iptables -t nat -A PREROUTING -i eth1 -s $redeINT -p tcp -d 65.54.53.57 --dport 443 -j DROP
echo "liberando faixa de ips permitidos"
iptables -A FORWARD -s 192.168.50.35 -p tcp --dport 1863 -j ACCEPT
iptables -A FORWARD -s 192.168.50.11 -p tcp --dport 1863 -j ACCEPT
iptables -A FORWARD -s 192.168.50.4 -p tcp --dport 1863 -j ACCEPT
iptables -A FORWARD -s 192.168.50.8 -p tcp --dport 1863 -j ACCEPT
iptables -A FORWARD -s 192.168.50.14 -p tcp --dport 1863 -j ACCEPT
iptables -A FORWARD -s 192.168.50.10 -p tcp --dport 1863 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.50.35 -p tcp --dport 1863 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.50.11 -p tcp --dport 1863 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.50.4 -p tcp --dport 1863 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.50.8 -p tcp --dport 1863 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.50.14 -p tcp --dport 1863 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.50.10 -p tcp --dport 1863 -j ACCEPT
echo "Fase 4 concluída!"
echo " "
echo " "
echo " "
###############################
# Proteções #
###############################
echo " "
echo "---->FASE 5<----"
echo " "
# Protege contra os "Ping of Death"
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 20/m -j ACCEPT
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 20/m -j ACCEPT
# Protege contra port scanners avançados (Ex.: nmap)
iptables -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 20/m -j ACCEPT
# Protecoes contra ataques
iptables -A INPUT -m state --state INVALID -j REJECT
echo "Fase 5 concluída!"
echo " "
echo " "
echo " "
echo "script finalizado com sucesso!!!"
se alguem poder me ajudar, eu agradeceria muito!