thiagoloki
(usa Nenhuma)
Enviado em 18/01/2011 - 10:35h
vou postar meu firewall, é até bom.. com certeza vai ter algumas falhas e vcs me ajudam a resolver..
echo "Habilitando o firewall"
echo "Limpando as tabelas"
iptables -t filter -F
iptables -t filter -X
iptables -t filter -Z
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
echo "Definindo politicas padrao"
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD DROP
iptables -t filter -P OUTPUT ACCEPT
echo "Aplicando regras de INPUT"
#Liberando trafego local
iptables -t filter -A INPUT -i lo -j ACCEPT
#Liberando trafego de INPUT com flag de conexao estabelecida
iptables -t filter -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#Regras do viva o linux
iptables -t nat -I POSTROUTING -o $ETH_WAN1 -p tcp --dport 443 -j MASQUERADE
iptables -I FORWARD -i $ETH_LAN1 -p tcp --dport 443 -j ACCEPT
#Regras de Ping
iptables -t filter -A INPUT -p icmp --icmp-type echo-request -j LOG --log-prefix 'Requisicao de Ping ->' --log-level debug
iptables -t filter -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -t filter -A INPUT -p icmp --icmp-type echo-reply -j LOG --log-prefix 'Resposta do Ping ->' --log-level debug
iptables -t filter -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_LAN1 -o $ETH_WAN1 -p icmp --icmp-type echo-request -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_WAN1 -o $ETH_LAN1 -p icmp --icmp-type echo-reply -j ACCEPT
# Proteções diversas contra portscanners, ping of death, ataques DoS, etc.
#iptables -t filter -A INPUT -m state --state INVALID -j DROP
#Liberando acesso ao squid
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p tcp --dport 3128 -j ACCEPT
#Liberando acesso ssh no servidor
iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT
#Liberando acesso ao apache (HTTP)
iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -t filter -A INPUT -p udp --dport 80 -j ACCEPT
#Liberando o servidor para acessar a internet (HTTP)
iptables -t filter -A INPUT -p tcp --sport 80 -j ACCEPT
iptables -t filter -A INPUT -p udp --sport 80 -j ACCEPT
#Liberando o HTTPS
iptables -t filter -A INPUT -i $ETH_WAN1 -p tcp --dport 443 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_WAN1 -p udp --dport 443 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_WAN1 -p tcp --sport 443 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_WAN1 -p udp --sport 443 -j ACCEPT
#Liberando o HTTPS para rede interna
iptables -t filter -A INPUT -i $ETH_LAN1 -p tcp --dport 443 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_LAN1 -p udp --dport 443 -j ACCEPT
#Liberando servico de DNS
iptables -t filter -A INPUT -p udp --dport 53 -j ACCEPT
#Aceitando respostas de servidores DNS externos
iptables -t filter -A INPUT -p udp --sport 53 -j ACCEPT
#Liberando acesso ao FTP
iptables -t filter -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 20 -j ACCEPT
#Liberando Acesso aos Compartilhamentos
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p tcp --dport 137 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p tcp --sport 137 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p udp --dport 137 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p udp --sport 137 -j ACCEPT
#
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p tcp --dport 138 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p tcp --sport 138 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p udp --dport 138 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p udp --sport 138 -j ACCEPT
#
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p tcp --dport 139 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p tcp --sport 139 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p udp --dport 139 -j ACCEPT
iptables -t filter -A INPUT -i $ETH_LAN1 -s $REDE_LAN1 -p udp --sport 139 -j ACCEPT
#Liberando Trafego do site CAIXA
iptables -t filter -A INPUT -s 200.201.174.207 -j ACCEPT
iptables -t filter -A FORWARD -s 200.201.174.207 -j ACCEPT
iptables -t filter -A FORWARD -d 200.201.174.207 -j ACCEPT
#
iptables -t filter -A INPUT -s 200.201.174.204 -j ACCEPT
iptables -t filter -A FORWARD -s 200.201.174.204 -j ACCEPT
iptables -t filter -A FORWARD -d 200.201.174.204 -j ACCEPT
#
iptables -t filter -A INPUT -s 200.201.173.68 -j ACCEPT
iptables -t filter -A FORWARD -s 200.201.173.68 -j ACCEPT
iptables -t filter -A FORWARD -d 200.201.173.68 -j ACCEPT
#Mascarando a Rede Interna e Forcando a Utilizacao PROXY
iptables -t nat -A POSTROUTING -s $REDE_LAN1 -o $ETH_WAN1 -j MASQUERADE
iptables -t nat -A PREROUTING -s $REDE_LAN1 -i $ETH_LAN1 -p tcp --dport 80 -j REDIRECT --to-ports 3128
echo "Aplicando regras de FORWARD"
#Dropando pacotes NEW sem syn
iptables -t filter -A FORWARD -p tcp ! --syn -m state --state NEW -j LOG --log-level 6 --log-prefix "FIREWALL: NEW sem syn: "
iptables -t filter -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
#Liberando trafego de FORWARD com flag de conexao estabelecida
iptables -t filter -A FORWARD -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
#Liberando ssh da rede interna para internet
iptables -t filter -A FORWARD -i $ETH_LAN1 -o $ETH_WAN1 -s $REDE_LAN1 -p tcp --dport 22 -j ACCEPT
#Liberando rede interna para acessar FTP
iptables -t filter -A FORWARD -p tcp --dport 20 -j ACCEPT
iptables -t filter -A FORWARD -p tcp --dport 21 -j ACCEPT
iptables -t filter -A FORWARD -p tcp --sport 20 -j ACCEPT
iptables -t filter -A FORWARD -p tcp --sport 21 -j ACCEPT
#Liberando 443 na rede interna
iptables -t filter -A FORWARD -p tcp --dport 443 -j ACCEPT
iptables -t filter -A FORWARD -p udp --dport 443 -j ACCEPT
iptables -t filter -A FORWARD -p tcp --sport 443 -j ACCEPT
iptables -t filter -A FORWARD -p udp --sport 443 -j ACCEPT
#Liberando o TeamViewer
iptables -t filter -A FORWARD -i $ETH_LAN1 -o $ETH_WAN1 -s $REDE_LAN1 -p tcp --dport 5938 -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_WAN1 -o $ETH_LAN1 -p tcp --sport 5938 -j ACCEPT
#Liberando Outlook para Rede Intera
iptables -t filter -A FORWARD -i $ETH_LAN1 -o $ETH_WAN1 -s $REDE_LAN1 -p tcp --dport 993 -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_LAN1 -o $ETH_WAN1 -s $REDE_LAN1 -p tcp --dport 587 -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_WAN1 -o $ETH_LAN1 -p tcp --sport 993 -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_WAN1 -o $ETH_LAN1 -p tcp --sport 587 -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_LAN1 -o $ETH_WAN1 -s $REDE_LAN1 -p udp --dport 993 -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_LAN1 -o $ETH_WAN1 -s $REDE_LAN1 -p udp --dport 587 -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_WAN1 -o $ETH_LAN1 -p udp --sport 993 -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_WAN1 -o $ETH_LAN1 -p udp --sport 587 -j ACCEPT
#Liberando Acesso Remoto mstsc
iptables -t filter -A FORWARD -i $ETH_WAN1 -o $ETH_LAN1 -d $SRV_WIN1 -p tcp --dport 3389 -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_LAN1 -o $ETH_WAN1 -s $REDE_LAN1 -p tcp --dport 3389 -j ACCEPT
iptables -t filter -A FORWARD -i $ETH_WAN1 -o $ETH_LAN1 -p tcp --sport 3389 -j ACCEPT
iptables -t nat -A PREROUTING -d $IP_EXT1 -p tcp --dport 3389 -j DNAT --to $SRV_WIN1
#iptables -t filter -A INPUT -j LOG --log-prefix "INPUT DROPADA -> "
#iptables -t filter -A FORWARD -j LOG --log-prefix "FORWARD DROPADA -> "
#Liberando repasse de pacotes
echo "Habilitando ip_forward"
echo 1 > /proc/sys/net/ipv4/ip_forward