brunosdf
(usa Debian)
Enviado em 17/06/2009 - 00:23h
Olá, gostaria de ajuda!
meu firewall nao bloqueia programas como emule e bittorrent, o que ha errado nas configs??
abaixo segue meu rc.firewall:
#!/bin/sh
# eth3 -> Rede interna (192.168.0.254/24)
# eth1 -> ADLS 1 (192.168.253.253/24)
# eth2 -> ADSL 2 (192.168.254.253/24)
# Variaveis
DNS1="201.10.120.2"
DNS2="201.10.128.3"
# Carregando os modulos basicos:
echo -n "Carregando os modulos..."
modprobe ip_tables
modprobe iptable_filter
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe iptable_nat
modprobe ip_nat_ftp
modprobe ipt_LOG
modprobe ipt_state
modprobe ipt_MASQUERADE
echo " [OK]"
# Resetando o Firewall:
echo -n "Resetando o firewall..."
iptables -F
iptables -Z
iptables -X
iptables -t nat -F
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
echo " [OK]"
# Habilitando o roteamento de pacotes:
echo -n "Habilitando o roteamento..."
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo " [OK]"
# Liberando a chain INPUT para o localhost:
echo -n "Liberando acesso do localhost..."
iptables -A INPUT -p ALL -s 127.0.0.1 -i lo -j ACCEPT
iptables -A INPUT -p ALL -s 192.168.0.254 -i lo -j ACCEPT
iptables -A INPUT -p ALL -s 192.168.243.253 -i lo -j ACCEPT
iptables -A INPUT -p ALL -s 192.168.254.253 -i lo -j ACCEPT
echo " [OK]"
# Otimizando o firewall:
echo -n "Otimizando o roteamento..."
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
echo " [OK]"
# Liberando resposta dos servidores DNS:
echo -n "Liberando servidores DNS..."
iptables -A INPUT -p udp -s 192.168.0.0/24 --sport 53 -d $DNS1 -j ACCEPT
iptables -A INPUT -p udp -s 192.168.0.0/24 --sport 53 -d $DNS2 -j ACCEPT
echo " [OK]"
# DHCP Server
echo -n "Liberando servidor DHCP..."
iptables -A INPUT -p udp -s 192.168.0.0/24 --sport 79 -d 192.168.0.254 -j ACCEPT
echo " [OK]"
# Descartar pacotes fragmentados:
echo -n "Bloqueando pacotes fragmentados..."
iptables -A INPUT -i eth1 -f -j LOG --log-prefix "Pacote fragmentado: "
iptables -A INPUT -i eth1 -f -j DROP
iptables -A INPUT -i eth2 -f -j LOG --log-prefix "Pacote Fragmentado: "
iptables -A INPUT -i eth2 -f -j DROP
echo " [OK]"
# Bloqueando ataques do tipo SPOOF de IP:
echo -n "Bloqueando spoofing..."
iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP
iptables -A INPUT -i eth1 -s 172.16.0.0/12 -j DROP
iptables -A INPUT -i eth1 -s 192.168.0.0/16 -j DROP
iptables -A INPUT -i eth1 -s 224.0.0.0/4 -j DROP
iptables -A INPUT -i eth1 -s 240.0.0.0/5 -j DROP
iptables -A INPUT -i eth2 -s 10.0.0.0/8 -j DROP
iptables -A INPUT -i eth2 -s 172.16.0.0/12 -j DROP
iptables -A INPUT -i eth2 -s 192.168.0.0/16 -j DROP
iptables -A INPUT -i eth2 -s 224.0.0.0/4 -j DROP
iptables -A INPUT -i eth2 -s 240.0.0.0/5 -j DROP
echo " [OK]"
# Liberando alguns acessos por ping:
echo -n "Liberando acesso por ping..."
iptables -A INPUT -p icmp --icmp-type 8 -i eth3 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 0 -j ACCEPT
iptables -A INPUT -p icmp -s 192.168.0.0/24 -d 0/0 -j ACCEPT
echo " [OK]"
# Liberando portas squid, ssh, samba, jacad, outlook, outros....
iptables -A INPUT -p TCP --dport 3128 -j ACCEPT
iptables -A INPUT -p UDP --dport 3128 -j ACCEPT
iptables -A INPUT -p TCP --dport 80 -j ACCEPT
iptables -A INPUT -p TCP --dport 22 -j ACCEPT
iptables -A INPUT -p TCP --dport 8080 -j ACCEPT
iptables -A INPUT -p TCP --dport 8090 -j ACCEPT
iptables -A INPUT -p TCP --dport 443 -j ACCEPT
iptables -A INPUT -p TCP --dport 137:139 -j ACCEPT
iptables -A INPUT -p UDP --dport 137:139 -j ACCEPT
iptables -A INPUT -p TCP --dport 445 -j ACCEPT
iptables -A INPUT -p TCP --dport 554 -j ACCEPT
iptables -A INPUT -p UDP --dport 197 -j ACCEPT
iptables -A INPUT -p UDP --dport 67 -j ACCEPT
iptables -A INPUT -p UDP --dport 68 -j ACCEPT
iptables -A INPUT -p UDP --dport 53 -j ACCEPT
iptables -A INPUT -p TCP --dport 587 -j ACCEPT
iptables -A INPUT -p TCP --dport 25 -j ACCEPT
iptables -A INPUT -p TCP --dport 110 -j ACCEPT
# Squid transparente
iptables -t nat -A PREROUTING -p TCP --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A PREROUTING -p UDP --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A PREROUTING -p TCP --dport 8080 -j REDIRECT --to-port 3128
#iptables -A FORWARD -p tcp --dport 1863 -j REJECT
# Regras do FORWARD
# Descarta pacotes invalidos:
echo -n "Descartando pacotes invalidos para reenvio..."
iptables -A FORWARD -m state --state INVALID -j DROP
echo " [OK]"
# Mantendo conexoes ativas:
echo -n "Manutencao de conexoes ativas..."
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
echo " [OK]"
# Liberando acesso ao DNS para a rede interna (Email):
echo -n "Liberando DNS para rede interna..."
iptables -A FORWARD -s 192.168.0.0/24 -j ACCEPT
iptables -A FORWARD -p udp -s 192.168.0.0/24 -d $DNS1 --dport 53 -j ACCEPT
iptables -A FORWARD -p udp -s 192.168.0.0/24 -d $DNS2 --dport 53 -j ACCEPT
iptables -A FORWARD -p udp -s $DNS1 --sport 53 -d 192.168.0.0/24 -j ACCEPT
iptables -A FORWARD -p udp -s $DNS2 --sport 53 -d 192.168.0.0/24 -j ACCEPT
echo " [OK]"
echo -n "Habilitando o mascaramento..."
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE
echo " [OK]"
# Desabilitando o filtro de pacotes do martian source
echo -n "Desligando rp_filter..."
for eee in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo 0 > $eee
done
echo " [OK]"
# Definindo regras de balanceamento de Link:
echo -n "Balanceando links adsl..."
ip route flush table adsl1
ip route flush table adsl2
# adsl #1
ip route add 192.168.253.0/24 dev eth1 src 192.168.253.253 table adsl1
ip route add default via 192.168.253.254 dev eth1 table adsl1
ip rule add from 192.168.253.253 table adsl1
# adsl #2
ip route add 192.168.254.0/24 dev eth2 src 192.168.254.253 table adsl2
ip route add default via 192.168.254.254 dev eth2 table adsl2
ip rule add from 192.168.254.253 table adsl2
# setando adsl na tabela principal de roteamento
ip route add 192.168.0.0/24 dev eth3 src 192.168.0.254
# balanceamento de link
ip route add default scope global nexthop via 192.168.253.254 dev eth1 weight 2 nexthop via 192.168.254.254 dev eth2 weight 1
# flush no roteamento
ip route flush cache
echo " [OK]"