fabkons
(usa Outra)
Enviado em 16/03/2009 - 13:58h
segue cara tenho na minha rede interna um servidor com o ip 192.168.1.100:9090/workflow esse e o caminho da minha aplicacao, fiz uma nat para acesso externo que ficou assim 200.146.120.66:9090/workflow de fora da empresa consigo acessar a aplicacao mais de dentro da minha rede nao consigo minha saida pra internet to usando o mesmo ip 200.146.120.66
Muito obrigado
#!/bin/bash
# description: Iniciando Firewall
# chkconfig: 345 80 30
# pidfile: /var/run/firewall.pid
iptables=/sbin/iptables
# Enderecos IPs do Firewall
#ip_ext1=201.47.73.165
ip_ext1=200.146.120.66
ip_ext2=201.3.192.218
ip_ext3=200.215.17.190
ip_int=192.168.1.254
ip_lo=127.0.0.1
# Interfaces
if_int=eth0
if_ext1=eth1
if_ext2=eth2
if_ext3=eth3
if_lo=lo
# Servidores
hermes1=201.3.192.219
hermes2=200.215.17.186
work=200.146.120.66
osiris=201.3.192.218
opens1=201.34.141.194
opens2=201.67.155.8/29
# Rede Interna
intranet=192.168.1.0/24
wts=192.168.1.121
workflow=192.168.1.100
# DMZ
dmz_net1=200.215.17.184/29
dmz_net2=201.3.192.216/29
# Gerar log's (yes/no) ?
LOGGING=yes
# debug ?
DEBUG=no
iptables_bin() {
if [ "$DEBUG" == "yes" -o "$DEBUG" == "YES" ]
then
echo "Executando: iptables $@"
$iptables "$@"
else
$iptables "$@"
fi
}
do_log() {
if [ "$LOGGING" == "yes" -o "$LOGGING" == "YES" ]
then
iptables_bin "$@"
fi
}
action() {
loop=1
for args in "$@"
do
if [ $loop -eq 1 ];then
echo -en "$1 ..."
else
cmd="$cmd $args"
fi
loop=`expr $loop + 1`
done
/bin/sh $cmd
if [ $? -eq 0 ];then
echo "done"
else
echo "failed"
fi
}
start() {
# Habilitando encaminhamento de pacotes de outras máquinas
echo 1 > /proc/sys/net/ipv4/ip_forward
# Protecao contra IP Spoofing #
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo 1 >$i
done
# Limpando o firewall
iptables_bin -t mangle -F
iptables_bin -t nat -F
iptables_bin -F
iptables_bin -X bad_tcp 2> /dev/null
iptables_bin -X allow_icmp 2> /dev/null
iptables_bin -N bad_tcp
iptables_bin -N allow_icmp
iptables_bin -P INPUT DROP
iptables_bin -P FORWARD DROP
iptables_bin -P OUTPUT DROP
#=========== Mascarando Conexoes da rede interna com destino a Internet (Link RADIO) ===============#
# TCP
iptables_bin -t nat -A POSTROUTING -o $if_ext1 -s $intranet -p tcp -j MASQUERADE
# UDP
iptables_bin -t nat -A POSTROUTING -o $if_ext1 -s $intranet -p udp -j MASQUERADE
# ICMP
iptables_bin -t nat -A POSTROUTING -o $if_ext1 -s $intranet -p icmp -j MASQUERADE
#========== Mascarando Conexoes da rede interna com destino a Internet (Link 512) ================#
# TCP
iptables_bin -t nat -A POSTROUTING -o $if_ext2 -s $intranet -p tcp -j MASQUERADE
# UDP
iptables_bin -t nat -A POSTROUTING -o $if_ext2 -s $intranet -p udp -j MASQUERADE
# ICMP
iptables_bin -t nat -A POSTROUTING -o $if_ext2 -s $intranet -p icmp -j MASQUERADE
#========== Mascarando Conexoes da rede interna com destino a Internet (Link 256) ================#
# TCP
iptables_bin -t nat -A POSTROUTING -o $if_ext3 -s $intranet -p tcp -j MASQUERADE
# UDP
iptables_bin -t nat -A POSTROUTING -o $if_ext3 -s $intranet -p udp -j MASQUERADE
# ICMP
iptables_bin -t nat -A POSTROUTING -o $if_ext3 -s $intranet -p icmp -j MASQUERADE
#================== PREROUTING - Redirecionamento de Pacotes ===================#
# Conectividade Social CAIXA
CAIXA_OK="192.168.1.1 192.168.1.36 192.168.1.78 192.168.1.55 192.168.1.54 192.168.1.19 192.168.1.14 192.168.1.98 192.168.1.121 192.168.1.40 192.168.1.121 192.168.1.22 192.168.1.146 192.168.47 192.168.1.65 192.168.1.62 192.168.1.212 192.168.1.24 192.168.1.51 192.168.1.121 192.168.1.24 192.168.1.97 192.168.1.44 192.168.1.93 192.168.1.94 192.168.1.99"
for IPS in $CAIXA_OK; do
iptables_bin -t nat -I POSTROUTING -s $IPS -p ALL -j MASQUERADE
iptables_bin -t nat -I PREROUTING -s $IPS -p ALL -j ACCEPT
iptables_bin -I FORWARD -s $IPS -p ALL -j ACCEPT
done
# CAIXA_OK="192.168.1.121 192.168.1.120 192.168.1.93 192.168.1.94 192.168.1.33 192.168.1.55"
# for IPS in $CAIXA_OK; do
# iptables_bin -t nat -I PREROUTING -s $IPS -d 200.201.173.68 -p tcp --dport 80 -j ACCEPT
# iptables_bin -I FORWARD -s $IPS -d 200.201.173.68 -p ALL -j ACCEPT
# iptables_bin -t nat -I PREROUTING -s $IPS -d 200.201.174.207 -p tcp --dport 80 -j ACCEPT
# iptables_bin -I FORWARD -s $IPS -d 200.201.174.207 -p ALL -j ACCEPT
# iptables_bin -t nat -I PREROUTING -s $IPS -d 200.201.173.68 -p ALL -j ACCEPT
# iptables_bin -I FORWARD -s $IPS -d 200.201.173.68 -p ALL -j ACCEPT
# done
# Proxy Transparente
iptables_bin -t nat -A PREROUTING -i $if_int -s $intranet -p tcp --dport 80 -j DNAT --to $ip_int:3128
# Software Workflow
iptables_bin -t nat -A PREROUTING -i $work -d $work -p tcp --dport 9090 -j DNAT --to $work
iptables_bin -t nat -A PREROUTING -i $if_ext2 -d $ip_ext2 -p tcp --dport 9090 -j DNAT --to $workflow
iptables_bin -t nat -A PREROUTING -i $if_ext3 -d $ip_ext3 -p tcp --dport 9090 -j DNAT --to $workflow
#==========================TCP REJEITADOS=============================#
iptables_bin -A bad_tcp -p ALL -m state --state INVALID -j DROP
iptables_bin -A bad_tcp -p tcp ! --syn -m state --state NEW -j DROP
iptables_bin -A bad_tcp -p tcp --tcp-flags SYN,ACK SYN,ACK -m state --state NEW -j REJECT --reject-with tcp-reset
iptables_bin -A bad_tcp -p ALL -m state --state INVALID -j LOG --log-level debug --log-prefix "Pacote TCP Invalido: "
#==========================ICMP AUTORIZADOS===========================#
iptables_bin -A allow_icmp -s $intranet -p icmp --icmp-type 8 -j ACCEPT
iptables_bin -A allow_icmp -s $intranet -p icmp --icmp-type 0 -j ACCEPT
iptables_bin -A allow_icmp -s $dmz_net1 -p icmp --icmp-type 8 -j ACCEPT
iptables_bin -A allow_icmp -s $dmz_net1 -p icmp --icmp-type 0 -j ACCEPT
iptables_bin -A allow_icmp -s $dmz_net2 -p icmp --icmp-type 8 -j ACCEPT
iptables_bin -A allow_icmp -s $dmz_net2 -p icmp --icmp-type 0 -j ACCEPT
#===================PASSANDO PARA A CHAIN INPUT======================#
#=======Consultas para pacotes com destino ao próprio Firewall=======#
iptables_bin -A INPUT -j bad_tcp
iptables_bin -A INPUT -j allow_icmp
# Permitindo Localhost
iptables_bin -A INPUT -p ALL -i $if_lo -j ACCEPT
iptables_bin -A INPUT -p ALL -s $ip_lo -j ACCEPT
iptables_bin -A INPUT -p ALL -s $ip_int -j ACCEPT
iptables_bin -A INPUT -p ALL -s $ip_ext1 -j ACCEPT
iptables_bin -A INPUT -p ALL -s $ip_ext2 -j ACCEPT
iptables_bin -A INPUT -p ALL -s $ip_ext3 -j ACCEPT
iptables_bin -A INPUT -p ALL -s $osiris -j ACCEPT
# Regras referente a rede interna
iptables_bin -A INPUT -i $if_int -s $intranet -p tcp -m multiport --dport 2522,3128,9090,10000 -j ACCEPT
# regras temporarias de acesso externo
iptables_bin -A INPUT -i $work -s $work -p tcp --dport 9090 -j ACCEPT
iptables_bin -A FORWARD -s $work -p tcp --dport 9090 -j ACCEPT
# Mantem conexoes estabelecidas
iptables_bin -I INPUT -p ALL -m state --state ESTABLISHED,RELATED -j ACCEPT
#====================LOGANDO PACOTES INPUT MORTOS======================#
iptables_bin -A INPUT -m limit --limit 1/minute --limit-burst 3 -j LOG \
--log-level debug --log-prefix "PACOTE IN MORTO: "
#===================PASSANDO PARA A CHAIN FORWARD======================#
iptables_bin -A FORWARD -j bad_tcp
iptables_bin -A FORWARD -j allow_icmp
# Acesso externo ao WTS
iptables_bin -A FORWARD -o $if_int -d $wts -p tcp --dport 3389 -j ACCEPT
# Acesso externo ao Sienge (Windows)
iptables_bin -A FORWARD -o $if_int -d $wts -p tcp --dport 8080 -j ACCEPT
# Acesso externo ao Worflow
iptables_bin -A FORWARD -o $if_int -d $workflow -p tcp --dport 9090 -j ACCEPT
# CAT comunicação de acidente de trabalho na previdencia
iptables_bin -I FORWARD -i $if_int -s $intranet -d 200.152.32.148 -p tcp --dport 5017 -j ACCEPT
# Sistema Conectividade Social(Link 512K)
iptables_bin -A FORWARD -i $if_ext1 -s $intranet -d 200.201.174.207 -p tcp -j ACCEPT
iptables_bin -A FORWARD -i $if_ext1 -s $intranet -p tcp --dport 3456 -j ACCEPT
# Sistema Conectividade Social(Link 256K)
iptables_bin -A FORWARD -i $if_int -s $intranet -d 200.201.174.207 -p tcp -j ACCEPT
iptables_bin -A FORWARD -i $if_int -s $intranet -p tcp --dport 3456 -j ACCEPT
# Conexoes com origem a rede interna e destino a Internet(Link 512K)
iptables_bin -A FORWARD -i $if_int -s $intranet -p tcp -m multiport --dport 20,21,123,443,1863,9090,1864 -j ACCEPT
iptables_bin -A FORWARD -i $if_int -s $intranet -p udp -m multiport --dport 53,9090,123 -j ACCEPT
# Conexoes com origem a rede interna e destino ao Servidor de Email
iptables_bin -A FORWARD -i $if_int -s $intranet -d $hermes1 -p tcp -j ACCEPT
iptables_bin -A FORWARD -i $if_int -s $intranet -d $hermes2 -p tcp -j ACCEPT
#conexao com origem a rede interna workflow
iptables_bin -A FORWARD -i $if_int -s $intranet -d $work -p tcp -j ACCEPT
# Pacote destinados a DMZ (work) com origem a Internet (Link a Radio)
iptables_bin -A FORWARD -d $work -p udp --dport 53 -j ACCEPT
iptables_bin -A FORWARD -d $work -p tcp -m multiport --dport 9090 -j ACCEPT
# Pacotes destinados a DMZ (Hermes) com origem a Internet(Link 512k)
iptables_bin -A FORWARD -d $hermes1 -p udp --dport 53 -j ACCEPT
iptables_bin -A FORWARD -d $hermes1 -p tcp -m multiport --dport 25,9090,80,110,143 -j ACCEPT
iptables_bin -A FORWARD -d $hermes1 -p tcp -m multiport --dport 443,993,995 -j ACCEPT
# Pacotes destinados a DMZ (Hermes) com origem a Internet(Link 256k)
iptables_bin -A FORWARD -d $hermes2 -p udp --dport 53 -j ACCEPT
iptables_bin -A FORWARD -d $hermes2 -p tcp -m multiport --dport 25,9090,80,110,143 -j ACCEPT
iptables_bin -A FORWARD -d $hermes2 -p tcp -m multiport --dport 443,465,993,995 -j ACCEPT
# Mantem conexoes estabelecidas
iptables_bin -A FORWARD -p ALL -m state --state ESTABLISHED,RELATED -j ACCEPT
#====================LOGANDO PACOTES FORWARD MORTOS======================#
iptables_bin -A FORWARD -m limit --limit 1/minute --limit-burst 3 -j LOG \
--log-level debug --log-prefix "PACOTE FW MORTO: "
#======================PASSANDO PARA A CHAIN OUTPUT======================#
#========== Conexoes originadas pelo proprio Firewall ================#
iptables_bin -A OUTPUT -p ALL -s $ip_lo -j ACCEPT
iptables_bin -A OUTPUT -p ALL -s $ip_int -j ACCEPT
iptables_bin -A OUTPUT -p ALL -s $ip_ext1 -j ACCEPT
iptables_bin -A OUTPUT -p ALL -s $ip_ext2 -j ACCEPT
iptables_bin -A OUTPUT -p ALL -s $ip_ext3 -j ACCEPT
iptables_bin -A OUTPUT -p ALL -m state --state ESTABLISHED,RELATED -j ACCEPT
#====================LOGANDO PACOTES OUTPUT MORTOS======================#
iptables_bin -A OUTPUT -m limit --limit 1/minute --limit-burst 3 -j LOG \
--log-level debug --log-prefix "PACOTE OUT MORTO: "
}
stop() {
iptables_bin -F
iptables_bin -F -t nat
iptables_bin -F -t mangle
iptables_bin -X bad_tcp 2>/dev/null
iptables_bin -X allow_icmp 2> /dev/null
iptables_bin -P INPUT ACCEPT
iptables_bin -P OUTPUT ACCEPT
iptables_bin -P FORWARD ACCEPT
# Desbilitando encaminhamento de pacotes de outras máquinas
echo 0 >/proc/sys/net/ipv4/ip_forward
}
status(){
echo -en "\{TTEXTO}33[1;34m"
echo "Listagem de Regras de NAT ativas:"
echo -en "\{TTEXTO}33[0;39m"
iptables_bin -nL -t nat -v |more
echo -en "\{TTEXTO}33[1;34m"
echo "Listagem de Regras de MANGLE ativas:"
echo -en "\{TTEXTO}33[0;39m"
iptables_bin -nL -t mangle -v |more
echo -en "\{TTEXTO}33[1;34m"
echo "Prescione <enter> para continuar"
echo -en "\{TTEXTO}33[0;39m"
read x
echo -en "\{TTEXTO}33[1;34m"
echo "Listagem de Regras de Filtragem ativas:"
echo -en "\{TTEXTO}33[0;39m"
iptables_bin -nL -v |sed s/Chain/Regras/g|more
}
case $1 in
start)
action "Iniciando o Firewall" $0 funcstart
;;
stop)
action "Interrompendo Firewall" $0 funcstop
;;
status)
status
;;
funcstart)
start&
;;
funcstop)
stop
;;
*)
echo "Use $0 start|stop|status"
exit 0
;;
esac