felipe.augusto13
(usa Ubuntu)
Enviado em 11/02/2012 - 19:17h
Oi galera...
Preciso de uma ajuda, estou construindo um firewall e não está funcionando um redirecionamento DNAT para um servidor Terminal na porta 3388.
Já analisei muito,estudei bastante mais consegui fazer funcionar o mesmo.
---------------------------------------------------------------------------------------------------------
#!/bin/bash
IPT=`which iptables`
IFLAN="eth1"
IFIBRA="ppp0"
function STOP () {
echo "Parando o Firewall"
$IPT -F
$IPT -t nat -F
$IPT -t mangle -F
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD ACCEPT
$IPT -X
$IPT -t nat -X
$IPT -t mangle -X
echo "Sem Firewall"
}
function START (){
echo "Iniciando Firewall"
#COMPARTILHAR INTERNET
echo 1 > /proc/sys/net/ipv4/ip_forward
$IPT -t nat -A POSTROUTING -o $IFIBRA -j SNAT --to meu ip
#PROTECAO CONTRA DOS PING
$IPT -A INPUT -p icmp --icmp-type 8 -m limit --limit 8/s -j ACCEPT
$IPT -A INPUT -p icmp --icmp-type 0 -m limit --limit 8/s -j ACCEPT
#PROTECAO CONTRA SYN-FLOOD PARA SPEEDY
$IPT -N isynflood
$IPT -A INPUT -i $IFIBRA -p tcp --syn -j isynflood
$IPT -A isynflood -m limit --limit 1/s --limit-burst 4 -j RETURN
$IPT -A isynflood -j DROP
#BLOQUEANDO PACOTES INVALIDOS
$IPT -A INPUT -m state --state INVALID -j DROP
$IPT -A FORWARD -m state --state INVALID -j DROP
#BLOQUEAR POR MAC ADDRESS
#$IPT -A INPUT -m mac --mac-source ! 00:11:22:33:44:55 -j DROP
#LIBERANDO PORTAS PARA REDE COM NEW,ESTABLISHED,RELATED
$IPT -A FORWARD -m state --state NEW,ESTABLISHED,RELATED -p udp -m multiport --dports 53,123 -j ACCEPT
$IPT -A FORWARD -m state --state NEW,ESTABLISHED,RELATED -p udp -m multiport --sports 53,123 -j ACCEPT
$IPT -A FORWARD -m state --state NEW,ESTABLISHED,RELATED -p tcp -m multiport --dports 80,53,20,21,22,25,110,443,587 -j ACCEPT
$IPT -A FORWARD -m state --state NEW,ESTABLISHED,RELATED -p tcp -m multiport --sports 80,53,20,21,22,25,110,443,587 -j ACCEPT
#DNAT PREROUTING
$IPT -t nat -A PREROUTING -i $IFIBRA -p tcp --dport 3388 -j DNAT --to 192.168.0.248
$IPT -A FORWARD -p tcp --sport 3388 -j ACCEPT
$IPT -A FORWARD -p tcp --dport 3388 -j ACCEPT
# ABRIR LOOPBACK
$IPT -A INPUT -i lo -j ACCEPT
$IPT -A OUTPUT -o lo -j ACCEPT
#PROTECAO CONTRA IP SPOOFING
# $IPT -A INPUT -s 172.16.18.0/24 -i $IFLAN -j DROP
#LIBERANDO PORTAS PARA SERVIDOR NEW,ESTABLISHED,RELATED
$IPT -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p udp -s 192.168.0.0/24 -j ACCEPT
$IPT -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p tcp -s 192.168.0.0/24 -j ACCEPT
$IPT -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p udp -m multiport --dports 53 -j ACCEPT
$IPT -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p tcp -m multiport --dports 5353,80,20,21,2223 -j ACCEPT
$IPT -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p udp -m multiport --sports 53,123 -j ACCEPT
$IPT -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p tcp -m multiport --sports 80,20,21,2223 -j ACCEPT
#OTIMIZANDO O SERVIDOR WEB
#$IPT -t mangle -A INPUT -p tcp --dport 80 -j TOS --set-tos 16
#$IPT -t mangle -A OUTPUT -p tcp --dport 80 -j TOS --set-tos 16
#$IPT -A FORWARD -j LOG --log-prefix="FELLIPE"
#POLITICA PADRAO
$IPT -P INPUT DROP
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD DROP
}
case $1 in
start)
START
;;
stop)
STOP
;;
restart)
STOP
sleep 3
START
;;
*)
echo "Erro no comando, digite $0 {start|stop|restart}"
;;
esac