jorgevisentini
(usa CentOS)
Enviado em 09/04/2012 - 23:21h
Pessoal eu criei um script de firewall bloqueando a entradade pacotes no firewall e nas máquinas, mas liberando a saída do firewall...
Bom... com esse script eu consigo acessar o compartilhamento do samba que eu criei, ssh, ping e mais algumas coisas... mas não consigo navegar na internet.
Bom... já sei que é o firewall porque quando eu libero todo ele, funciona...
Segue o script para analisarem...
#!/bin/sh
#VARIÁVEIS
iptables=/sbin/iptables
IF_INTERNA=eth0 - //192.168.130.1
IF_EXTERNA=eth1 - //dhcp
#rede_interna=192.168.130.0/24
#ATIVA OS MÓDULOS
modprobe iptable_nat
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ipt_LOG
modprobe ipt_MASQUERADE
modprobe ip_tables
modprobe iptable_nat
#ATIVA O ROTEAMENTO NO KERNEL
echo 1 > /proc/sys/net/ipv4/ip_forward
#PROTEÇÃO CONTRA IP SPOOFING
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
#LIMPA AS REGRAS
$iptables -F
$iptables -X
$iptables -F -t nat
$iptables -X -t nat
$iptables -F -t mangle
$iptables -X -t mangle
$iptables -F -t filter
$iptables -X -t filter
#DETERMINA A POLITICA PADRÃO
$iptables -P INPUT DROP
$iptables -P OUTPUT ACCEPT
$iptables -P FORWARD DROP
#CONEXOES ESTABELECIDAS
$iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
#REGRAS DE ENTRADA NO FIREWALL
#LOOPBACK
$iptables -A INPUT -i lo -j ACCEPT
#PING
$iptables -A INPUT -p icmp -j ACCEPT
#SSH
$iptables -A INPUT -p tcp --sport 22 -j ACCEPT
$iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#SAMBA
#$iptables -A INPUT -p tcp --sport 137:139 -j ACCEPT
$iptables -A INPUT -p tcp --dport 137:139 -j ACCEPT
#DNS
$iptables -A INPUT -p tcp --sport 53 -j ACCEPT
$iptables -A INPUT -p tcp --dport 53 -j ACCEPT
$iptables -A INPUT -p udp --sport 53 -j ACCEPT
$iptables -A INPUT -p udp --dport 53 -j ACCEPT
#REDE INTERNA
$iptables -A INPUT -s 192.168.0.0/22 -j ACCEPT
$iptables -A INPUT -d 192.168.0.0/22 -j ACCEPT
#PORTA RELOGIO/CATRACA
$iptables -A INPUT -p tcp --dport 3000 -j ACCEPT
#WEBMIN
$iptables -A INPUT -p tcp --dport 10000 -j ACCEPT
#IPS FALSO
$iptables -A INPUT -s 10.153.109.0/24 -j ACCEPT
$iptables -A INPUT -d 10.153.109.0/24 -j ACCEPT
#IPS VERDADEIROS
$iptables -A INPUT -s 200.203.124.0/24 -j ACCEPT
$iptables -A INPUT -d 200.203.124.0/24 -j ACCEPT
#IPS GVT RIA
$iptables -A INPUT -s 200.175.110.0/24 -j ACCEPT
$iptables -A INPUT -d 200.175.110.0/24 -j ACCEPT
#VPN
$iptables -A INPUT -s 10.8.0.0/24 -j ACCEPT
$iptables -A INPUT -d 10.8.0.0/24 -j ACCEPT
#MSN
$iptables -A INPUT -p tcp --sport 1863 -j ACCEPT
$iptables -A INPUT -p tcp --dport 1863 -j ACCEPT
#SAIDAS DO FIREWALL
#LOOPBACK
$iptables -A OUTPUT -o lo -j ACCEPT
#PING
$iptables -A OUTPUT -p icmp -j ACCEPT
#SSH
$iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
$iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
#SAMBA
$iptables -A OUTPUT -p tcp --sport 137:139 -j ACCEPT
#$iptables -A OUTPUT -p tcp --dport 137:139 -j ACCEPT
#DNS
$iptables -A OUTPUT -p tcp --sport 53 -j ACCEPT
$iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
$iptables -A OUTPUT -p udp --sport 53 -j ACCEPT
$iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
#REDE INTERNA
$iptables -A OUTPUT -s 192.168.0.0/22 -j ACCEPT
$iptables -A OUTPUT -d 192.168.0.0/22 -j ACCEPT
#PORTA RELOGIO/CATRACA
$iptables -A OUTPUT -p tcp --dport 3000 -j ACCEPT
#WEBMIN
$iptables -A OUTPUT -p tcp --dport 10000 -j ACCEPT
#IPS FALSO
$iptables -A OUTPUT -s 10.153.109.0/24 -j ACCEPT
$iptables -A OUTPUT -d 10.153.109.0/24 -j ACCEPT
#IPS VERDADEIROS
$iptables -A OUTPUT -s 200.203.124.0/24 -j ACCEPT
$iptables -A OUTPUT -d 200.203.124.0/24 -j ACCEPT
#IPS GVT RIA
$iptables -A OUTPUT -s 200.175.110.0/24 -j ACCEPT
$iptables -A OUTPUT -d 200.175.110.0/24 -j ACCEPT
#VPN
$iptables -A OUTPUT -s 10.8.0.0/24 -j ACCEPT
$iptables -A OUTPUT -d 10.8.0.0/24 -j ACCEPT
#MSN
$iptables -A OUTPUT -p tcp --sport 1863 -j ACCEPT
$iptables -A OUTPUT -p tcp --dport 1863 -j ACCEPT
#ACESSOS DA REDE INTERNAR PARA FORA
#LOOPBACK
$iptables -A FORWARD -p icmp -j ACCEPT
#SSH
$iptables -A FORWARD -p tcp --sport 22 -j ACCEPT
$iptables -A FORWARD -p tcp --dport 22 -j ACCEPT
#DNS
$iptables -A FORWARD -p tcp --sport 53 -j ACCEPT
$iptables -A FORWARD -p tcp --dport 53 -j ACCEPT
$iptables -A FORWARD -p udp --sport 53 -j ACCEPT
$iptables -A FORWARD -p udp --dport 53 -j ACCEPT
#REDE INTERNA
$iptables -A FORWARD -s 192.168.0.0/22 -j ACCEPT
$iptables -A FORWARD -d 192.168.0.0/22 -j ACCEPT
#IPS FALSO
$iptables -A FORWARD -s 10.153.109.0/24 -j ACCEPT
$iptables -A FORWARD -d 10.153.109.0/24 -j ACCEPT
#IPS VERDADEIROS
$iptables -A FORWARD -s 200.203.124.0/24 -j ACCEPT
$iptables -A FORWARD -d 200.203.124.0/24 -j ACCEPT
#IPS GVT RIA
$iptables -A FORWARD -s 200.175.110.0/24 -j ACCEPT
$iptables -A FORWARD -d 200.175.110.0/24 -j ACCEPT
#MSN
$iptables -A FORWARD -p tcp --sport 1863 -j ACCEPT
$iptables -A FORWARD -p tcp --dport 1863 -j ACCEPT
#MSN
$iptables -A FORWARD -p tcp -s 64.4.34.39 --sport 1863 -j ACCEPT
$iptables -A FORWARD -p tcp -d 64.4.34.39 --dport 1863 -j ACCEPT
#MSN
$iptables -A FORWARD -p tcp -s login.live.com --sport 1863 -j ACCEPT
$iptables -A FORWARD -p tcp -d login.live.com --dport 1863 -j ACCEPT
################################
# TABELA NAT #
################################
#ATIVA MASCARAMENTO DE SAIDA - CONEXAO COM A INTERNET
$iptables -A POSTROUTING -t nat -o $IF_INTERNA -j MASQUERADE
#PROXY TRANSPARENTE
$iptables -t nat -A PREROUTING -i $IF_INTERNA -p tcp --dport 80 -j REDIRECT --to-port 3128
#$iptables -t nat -A PREROUTING -i $IF_INTERNA -p tcp --dport 443 -j REDIRECT --to-port 3128