mr_marcinho
(usa Ubuntu)
Enviado em 17/05/2008 - 18:16h
Eu peguei um script firewall pronto, ja esta em uso e funcional, mas eu gostaria de fazer um redirecionamento para o VNC, e não estou conseguindo, se alguém puder me ajudar
#!/bin/bash
if [ -n "$1" ] && [ "$1" = "q" ]
then
QUIET="1"
else
QUIET="0"
fi
#FECHA=$(date +"%C%y-%m-%d %H:%M")
#echo $FECHA
#/usr/bin/logger -p kern.notice -t NETFILTER \
# "====== Iniciado Firewall: $FECHA ========="
if [ $QUIET = "0" ]; then
echo "
www.teste.com.br"
echo " ----------------------"
fi
if [ $QUIET = "0" ]; then
echo " Carregando parametros..."
fi
IPTABLES=/sbin/iptables
EXT_IF=eth0
EXT_IP=10.1.1.254
LAN_IF=eth1
LAN_IP=192.168.1.254
LAN_RED=192.168.1.0/24
LOO_RED=127.0.0.0/8
ANY_RED=0.0.0.0/0
#IP_SERVIDOR_FTP=192.168.1.2
if [ $QUIET = "0" ]; then
echo " Carregando modulos..."
fi
modprobe ip_conntrack_irc
modprobe ip_conntrack_ftp
modprobe ip_nat_irc
modprobe ip_nat_ftp
if [ $QUIET = "0" ]; then
echo " Limpando FW..."
fi
$IPTABLES -F
$IPTABLES -X
$IPTABLES -Z
$IPTABLES -t nat -F
$IPTABLES -t nat -X
if [ $QUIET = "0" ]; then
echo " Estabelecendo politicas..."
fi
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT DROP
$IPTABLES -P FORWARD DROP
$IPTABLES -t nat -P PREROUTING DROP
$IPTABLES -t nat -P POSTROUTING DROP
$IPTABLES -A OUTPUT -o $LAN_IF -s $LAN_IP -j ACCEPT
$IPTABLES -A OUTPUT -o $EXT_IF -s $EXT_IP -j ACCEPT
if [ $QUIET = "0" ]; then
echo " -> Negando redes invalidas..."
fi
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -s 192.168.0.0/16 -j DROP
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -s 10.0.0.0/8 -j DROP
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -s 172.16.0.0/12 -j DROP
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -s 224.0.0.0/4 -j DROP
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -s 240.0.0.0/5 -j DROP
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -s $LOO_RED -j DROP
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -s 0.0.0.0/8 -j DROP
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -s 169.254.0.0/16 -j DROP
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -s 255.255.255.255 -j DROP
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -s $EXT_IP -j DROP
$IPTABLES -t nat -A PREROUTING -i $LAN_IF -s ! $LAN_RED -j DROP
if [ $QUIET = "0" ]; then
echo " -> negando broadcast de NetBIOS..."
fi
iptables -A FORWARD -p tcp --sport 137:139 -o $EXT_IF -j DROP
iptables -A FORWARD -p udp --sport 137:139 -o $EXT_IF -j DROP
iptables -A OUTPUT -p tcp --sport 137:139 -o $EXT_IF -j DROP
iptables -A OUTPUT -p udp --sport 137:139 -o $EXT_IF -j DROP
if [ $QUIET = "0" ]; then
echo " Ativando NAT..."
fi
echo 1 > /proc/sys/net/ipv4/ip_forward
$IPTABLES -t nat -A POSTROUTING -s $LAN_RED -o $EXT_IF -j MASQUERADE
if [ $QUIET = "0" ]; then
echo " Permitindo accesso da maquina local..."
fi
if [ $QUIET = "0" ]; then
echo " -> loopback..."
fi
#$IPTABLES -A INPUT -i lo -j ACCEPT
#$IPTABLES -A OUTPUT -o lo -j ACCEPT
$IPTABLES -A INPUT -i lo -s $LOO_RED -d $LOO_RED -j ACCEPT
$IPTABLES -A OUTPUT -o lo -s $LOO_RED -d $LOO_RED -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -o lo -s $LOO_RED -j ACCEPT
if [ $QUIET = "0" ]; then
echo " -> LAN..."
fi
$IPTABLES -A INPUT -s $LAN_RED -i $LAN_IF -j ACCEPT
$IPTABLES -A OUTPUT -d $LAN_RED -o $LAN_IF -j ACCEPT
if [ $QUIET = "0" ]; then
echo " -> DNS..."
fi
$IPTABLES -A INPUT -s $ANY_RED -i $EXT_IF -p udp -m udp --sport 53 --dport 1024:65535 -j ACCEPT
$IPTABLES -A OUTPUT -d $ANY_RED -o $EXT_IF -p udp -m udp --dport 53 --sport 1024:65535 -j ACCEPT
if [ $QUIET = "0" ]; then
echo " -> ntpd..."
fi
$IPTABLES -A INPUT -p udp -m udp --dport 123 -i $EXT_IF -s $ANY_RED -j ACCEPT
$IPTABLES -A OUTPUT -p udp -m udp --sport 123 -j ACCEPT
if [ $QUIET = "0" ]; then
echo " -> icmp..."
fi
$IPTABLES -A INPUT -p icmp --icmp-type echo-request -m limit --limit 2/s -j ACCEPT
$IPTABLES -A OUTPUT -p icmp --icmp-type echo-request -m limit --limit 2/s -j ACCEPT
$IPTABLES -A INPUT -p icmp --icmp-type echo-reply -m limit --limit 2/s -j ACCEPT
$IPTABLES -A OUTPUT -p icmp --icmp-type echo-reply -m limit --limit 2/s -j ACCEPT
$IPTABLES -A INPUT -p icmp --icmp-type redirect -m limit --limit 2/s -j ACCEPT
$IPTABLES -A OUTPUT -p icmp --icmp-type redirect -m limit --limit 2/s -j ACCEPT
$IPTABLES -A INPUT -p icmp --icmp-type time-exceeded -m limit --limit 2/s -j ACCEPT
$IPTABLES -A OUTPUT -p icmp --icmp-type time-exceeded -m limit --limit 2/s -j ACCEPT
$IPTABLES -A INPUT -p icmp --icmp-type destination-unreachable -m limit --limit 2/s -j ACCEPT
$IPTABLES -A OUTPUT -p icmp --icmp-type destination-unreachable -m limit --limit 2/s -j ACCEPT
if [ $QUIET = "0" ]; then
echo " -> ssh..."
fi
#$IPTABLES -A INPUT -p tcp -i $EXT_IF -s $ANY_RED -m tcp --dport 2222 --sport 1024:65535 -j ACCEPT
$IPTABLES -A INPUT -p tcp -s $ANY_RED -m tcp --dport 2222 --sport 1024:65535 -m state --state NEW -j LOG --log-prefix "[FW - SSH] "
$IPTABLES -A INPUT -p tcp -s $ANY_RED -m tcp --dport 2222 --sport 1024:65535 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m tcp --sport 2222 -m state --state RELATED,ESTABLISHED -j ACCEPT
if [ $QUIET = "0" ]; then
echo " Redirecionamentos..."
fi
if [ $QUIET = "0" ]; then
echo " -> Proxy web transparente (Squid)..."
fi
$IPTABLES -t nat -A PREROUTING -d $LAN_RED -p tcp --dport 80 -j ACCEPT
$IPTABLES -t nat -A PREROUTING -i $LAN_IF -s $LAN_RED -p tcp --dport 80 -j REDIRECT --to-port 3128
$IPTABLES -A FORWARD -i $LAN_IF -p tcp --dport 80 -j DROP
if [ $QUIET = "0" ]; then
echo " -> Filtro de correio (P3Scan)..."
fi
$IPTABLES -t nat -A PREROUTING -i $LAN_IF -s $LAN_RED -p tcp --dport 110 -j REDIRECT --to-port 8110
$IPTABLES -A FORWARD -i $LAN_IF -p tcp --dport 110 -j DROP
###$IPTABLES -t nat -A OUTPUT -p tcp --dport 110 -m owner --owner-id p3scan -j ACCEPT
###$IPTABLES -t nat -A OUTPUT -p tcp --dport 110 -j REDIRECT --to-port 8110
if [ $QUIET = "0" ]; then
echo " -> DNAT (21 e 20)..."
fi
###$IPTABLES -t nat -A PREROUTING -i $EXT_IF -d $EXT_IP -p tcp --dport 21 -j LOG --log-prefix "[FW - FTP] "
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -d $EXT_IP -p tcp --dport 220 -j DNAT --to "$IP_SERVIDOR_FTP":20
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -d $EXT_IP -p tcp --dport 221 -j DNAT --to "$IP_SERVIDOR_FTP":21
$IPTABLES -t nat -A PREROUTING -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -o $LAN_IF -d $IP_SERVIDOR_FTP -p tcp --dport 20 -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -o $LAN_IF -d $IP_SERVIDOR_FTP -p tcp --dport 21 -j ACCEPT
$IPTABLES -A FORWARD -i $EXT_IF -d $IP_SERVIDOR_FTP -p tcp --dport 20 -j ACCEPT
$IPTABLES -A FORWARD -i $EXT_IF -d $IP_SERVIDOR_FTP -p tcp --dport 21 -j ACCEPT
if [ $QUIET = "0" ]; then
echo " Reenvios..."
fi
if [ $QUIET = "0" ]; then
echo " -> icmp..."
fi
$IPTABLES -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 2/s -j ACCEPT
$IPTABLES -A FORWARD -p icmp --icmp-type echo-reply -m limit --limit 2/s -j ACCEPT
$IPTABLES -A FORWARD -p icmp --icmp-type redirect -m limit --limit 2/s -j ACCEPT
$IPTABLES -A FORWARD -p icmp --icmp-type time-exceeded -m limit --limit 2/s -j ACCEPT
$IPTABLES -A FORWARD -p icmp --icmp-type destination-unreachable -m limit --limit 2/s -j ACCEPT
$IPTABLES -t nat -A PREROUTING -i $LAN_IF -p icmp --icmp-type any -m limit --limit 2/s -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -o $LAN_IF -p icmp --icmp-type any -m limit --limit 2/s -j ACCEPT
if [ $QUIET = "0" ]; then
echo " Quase Pronto..."
fi
$IPTABLES -A OUTPUT -o $EXT_IF -p tcp -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -i $EXT_IF -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $LAN_IF -j ACCEPT
$IPTABLES -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -t nat -A PREROUTING -i $LAN_IF -j ACCEPT
$IPTABLES -t nat -A PREROUTING -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -t nat -A PREROUTING -i $EXT_IF -d $EXT_IP -j ACCEPT
$IPTABLES -t nat -A PREROUTING -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -o $EXT_IF -s $EXT_IP -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -o $LAN_IF -s $LAN_RED -j ACCEPT
if [ $QUIET = "0" ]; then
echo " Fechando portas restritas..."
fi
$IPTABLES -A INPUT -p tcp --dport 1:1024 -j DROP
$IPTABLES -A INPUT -p udp --dport 1:1024 -j DROP
###$IPTABLES -t nat -A PREROUTING -j LOG --log-prefix "[FW - PR] "
###$IPTABLES -t nat -A POSTROUTING -j LOG --log-prefix "[FW - PO] "
###$IPTABLES -A FORWARD -j LOG --log-prefix "[FW - FW] "
###$IPTABLES -A INPUT -j LOG --log-prefix "[FW - IN] "
###$IPTABLES -A OUTPUT -j LOG --log-prefix "[FW - OU] "
if [ $QUIET = "0" ]; then
echo " Configuracao terminada."
echo ""
echo ""
fi
exit 0