lucianopqd
(usa Ubuntu)
Enviado em 08/05/2008 - 11:39h
Amigo faz o seguinte, eu tenho o que vc precisa mais vamos fazer por parte, primeiro coloca o seu firewall pra funcionar, já está com algumas regras inclusas e não precisa do squid até aqui, estou presumindo que sua internet seja velox:
echo "Ativando Dispositivos"
#-----------------------------------------------
EXTERNA=ppp+
INTERNA=eth+
REDELOCAL=192.168.1.0/255.255.255.0
echo "Ativando Módulos"
#-----------------------------------------------
modprobe iptable_nat
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp
modprobe ipt_LOG
modprobe ipt_REJECT
modprobe ipt_MASQUERADE
modprobe iptable_mangle
modprobe iptable_filter
modprobe ipt_TOS
echo "Limpando Regras"
#----------------------------------------------
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
iptables -F POSTROUTING -t nat
iptables -F PREROUTING -t nat
echo "Aplicando Regras"
#-----------------------------------------------
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
echo "Abrindo Conexão Inicial"
#-----------------------------------------------
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
echo "Aplicando Proteção contra Spoofing"
#-----------------------------------------------
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo "1" > $i
done
echo "Aplicando Proteção contra Syn-flood e ataque DoS"
#-----------------------------------------------
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
echo "Aplicando Proteção contra ping da morte"
#-----------------------------------------------
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
iptables -A FORWARD -p icmp --icmp-type echo-request -j DROP
echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo "Aplicando Proteção contra ataques"
#-----------------------------------------------
iptables -A INPUT -m state --state INVALID -j DROP
echo "Aplicando Proteção contra pacotes danificados"
#-----------------------------------------------
iptables -A INPUT -p icmp -s 192.168.1.1/24 -j DROP
echo "Aplicando proteção nos pacotes TCP indesejaveis"
#------------------------------------------------
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j LOG --log-level 6 --log-prefix "FIREWALL: NEW sem syn: "
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
echo "Aceitando retorno da internet"
#-----------------------------------------------
iptables -A INPUT -i ! $INTERNA -j ACCEPT
iptables -A INPUT -i ! $EXTERNA -j ACCEPT
iptables -A FORWARD -o $INTERNA -m state --state ESTABLISHED,RELATED -j ACCEPT
echo "Ativando roteamento"
#----------------------------------------------
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "Ativando Squid Local"
#----------------------------------------------
#iptables -A INPUT -p tcp --dport 3128 -i $INTERNA -j ACCEPT
echo "Mascarando Roteador"
#---------------------------------------------------
iptables -t nat -A POSTROUTING -s $REDELOCAL -o $EXTERNA -j MASQUERADE
echo "Ativando Proxy Transparente"
#------------------------------------------------
#iptables -t nat -A PREROUTING -i $INTERNA -p tcp --dport 80 -j REDIRECT --to-port 3128
#iptables -t nat -A PREROUTING -i $INTERNA -p tcp --dport 8080 -j REDIRECT --to-port 3128
echo "Acelerando Conexão"
#-----------------------------------------------
iptables -t mangle -A OUTPUT -p tcp -j TOS --sport 80 --set-tos 0x08
iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TOS --set-tos 0x08
iptables -t mangle -A OUTPUT -p tcp -j TOS --sport 80 --set-tos 0x10
echo "Abrindo LOOPBACK"
#-----------------------------------------------
iptables -A INPUT -p tcp -s 127.0.0.1/255.0.0.0 -j ACCEPT
echo "Abrindo portas externa"
#-----------------------------------------------
iptables -A FORWARD -i $EXTERNA -p tcp --dport https -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport imap -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport imap -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport www -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport domain -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport domain -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport ftp -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport ftp-data -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport ssh -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 53 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 53 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 25 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 25 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 110 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 110 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport ntp -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport ntp -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 3389 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 3389 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 3386 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 3386 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 3456 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 3456 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 143 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 143 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 465 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 446 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 446 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 995 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 5800:5900 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 5800:5900 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 5801:5901 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 5801:5901 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport smtp -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport smtp -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport pop-3 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport pop-3 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 2631 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 2631 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 5222:5223 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 5222:5223 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 20001:20005 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 20000:20019 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 5024 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 1024 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 3306 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 82 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p tcp --dport 953 -j ACCEPT
iptables -A FORWARD -i $EXTERNA -p udp --dport 953 -j ACCEPT
echo "Abrindo portas internas"
#-----------------------------------------------
iptables -A FORWARD -i $INTERNA -p tcp --dport https -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport imap -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport imap -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport domain -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport domain -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport ftp -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport ftp-data -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport ssh -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 53 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 53 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 25 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 25 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 110 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 110 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport ntp -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport ntp -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 3389 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 3389 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 3386 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 3386 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 3456 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 3456 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 143 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 143 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 465 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 446 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 446 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 995 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 5800:5900 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 5800:5900 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 5801:5901 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 5801:5901 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 10000 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 10000 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport smtp -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport smtp -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport pop-3 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport pop-3 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 2631 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 2631 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 5222:5223 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 5222:5223 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 20001:20005 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 20000:20019 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 5024 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 1024 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 306 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 82 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p tcp --dport 953 -j ACCEPT
iptables -A FORWARD -i $INTERNA -p udp --dport 953 -j ACCEPT
echo "Trocando Portas"
#------------------------------------------------
PORT_INI=61000
PORT_FIM=65095
echo $PORT_INI $PORT_FIM > /proc/sys/net/ipv4/ip_local_port_range
echo "Bloqueando pocotes não liberados"
#-----------------------------------------------
iptables -A FORWARD -j DROP
iptables -A INPUT -j DROP
echo
echo "Firewall Ativo!"