Agleson
(usa Debian)
Enviado em 10/03/2016 - 17:07h
Olá
10minutos
OBS:
tem algumas regras que não fui eu que fiz na verdade bastante.
Desde já agradeço sua atenção.
Segue regras de firewall abaixo:
#!/bin/bash
###########################################
# REGRAS FIREWALL PACOTILHA #
###########################################
echo "Iniciando firewall..."
echo "Desativando Forwarding..."
echo 0 > /proc/sys/net/ipv4/ip_forward
echo "Carregando as variaveis..."
##############
# Variaveis #
##############
###### INTERFACES FISICAS ######
IF_LAN0=eth0 # Rede local
IF_WAN1=eth1 # OI4MB
IF_WAN2=eth3 # NET10MB
IF_DMZ=eth4 # DMZ
IF_MPLS=eth2 # OIMPLS
###### IPS ######
IP_LAN=192.168.x.x # LAN
IP_WAN2=177.x.x.x # TVN10mb NEW
IP_DMZ=172.16.x.x # DMZ
###### REDES ######
REDE_LAN=192.168.0.0/24
REDE_MPLS=10.255.255.16
REDE_DMZ=172.16.x.x/24
####### SERVIDORES ######
CAMERAS=192.168.x.x
ADV01=192.168.x.x
ADV02=192.168.x.x
ARQUIVO=192.168.x.x
FTP=192.168.x.x
MAILHUB=192.168.x.x
INTRANET=192.168.x.x
MAILSRV=192.168.x.x
####################
# PORTAS #
####################
ENTRADA_TCP=/opt/salyx/fw/entrada.tcp
ENTRADA_UDP=/opt/salyx/fw/entrada.udp
SAIDA_TCP=/opt/salyx/fw/saida.tcp
SAIDA_UDP=/opt/salyx/fw/saida.udp
EXTERNO_TCP=/opt/salyx/fw/externo.tcp
EXTERNO_UDP=/opt/salyx/fw/externo.udp
###### ALIASE ######
IPT=/sbin/iptables
##### Modulos ######
echo "Carregando os modulos..."
modprobe ip_tables
modprobe ip_conntrack
modprobe ip_nat_ftp
modprobe ipt_REJECT
modprobe ipt_LOG
modprobe ipt_MASQUERADE
modprobe ip_conntrack_ftp
modprobe ipt_MARK
modprobe ipt_mark
modprobe ip_nat_pptp
modprobe pptp
###### Tabelas ######
echo "Limpando as tabelas ..."
$IPT -t nat -F
$IPT -t nat -X
$IPT -t nat -Z
$IPT -t mangle -F
$IPT -t mangle -X
$IPT -t mangle -Z
$IPT -F
$IPT -X
$IPT -Z
echo "Ativando regras..."
########################
# FILTER: INPUT #
########################
echo "TABELA INPUT"
$IPT -P INPUT DROP
$IPT -A INPUT -s 172.16.128.0/24 -j ACCEPT
$IPT -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
$IPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPT -A INPUT -m state --state INVALID -j DROP
$IPT -A INPUT -s 127.0.0.1 -j ACCEPT
$IPT -A INPUT -s 127.0.1.1 -j ACCEPT
$IPT -A INPUT -p tcp --dport 80 -d $IP_LAN -j ACCEPT
$IPT -A INPUT -i $IF_MPLS -j ACCEPT
$IPT -A INPUT -i $IF_WAN2 -p tcp --dport 3128 -j DROP
$IPT -A INPUT -i $IF_WAN1 -p tcp --dport 3128 -j DROP ##Adicionado dia 23 por igor
if [ -f $ENTRADA_TCP ]; then
for i in `cat $ENTRADA_TCP`; do
INTERFACE=`echo $i | cut -d ';' -f1`
if [ $INTERFACE = "LAN" ]; then
IFACE=$IF_LAN0;
else [ $INTERFACE = "WAN" ]
IFACE=$IF_WAN2;
fi
PORTA=`echo $i | cut -d ';' -f2`
$IPT -A INPUT -i $IFACE -p tcp --dport $PORTA -j ACCEPT
done
fi
if [ -f $ENTRADA_UDP ]; then
for i in `cat $ENTRADA_UDP`; do
INTERFACE=`echo $i | cut -d ';' -f1`
if [ $INTERFACE = "LAN" ]; then
IFACE=$IF_LAN0;
else [ $INTERFACE = "WAN" ]
IFACE=$IF_WAN2;
fi
PORTA=`echo $i | cut -d ';' -f2`
$IPT -A INPUT -i $IFACE -p udp --dport $PORTA -j ACCEPT
done
fi
if [ -f $EXTERNO_TCP ]; then
for i in `cat $EXTERNO_TCP`; do
PORTA=`echo $i | cut -d ';' -f1`
$IPT -A INPUT -i $IF_WAN2 -p tcp --dport $PORTA -j ACCEPT
done
fi
if [ -f $EXTERNO_UDP ]; then
for i in `cat $EXTERNO_UDP`; do
PORTA=`echo $i | cut -d ';' -f1`
$IPT -A INPUT -i $IF_WAN2 -p udp --dport $PORTA -j ACCEPT
done
fi
#liberacao voz contacta udp varias portas
#$IPT -A INPUT -i $IF_WAN2 -p udp --dport 10000:20000 -j ACCEPT
#$IPT -A INPUT -i $IF_LAN0 -p udp --dport 3000:65000 -j ACCEPT
#Libera ftp
$IPT -A INPUT -i $IF_WAN2 -p tcp -m multiport --dports 21,20 -j ACCEPT
$IPT -A INPUT -p tcp -m tcp --dport 50000:50030 -j ACCEPT
#FTP varias portas
#$IPT -A INPUT -i $IF_WAN2 -p tcp --dport 27000:28000 -j ACCEPT
########################
# FILTER: FORWARD #
########################
echo "Ativando Forward"
####################################################
# ENDERECOS INTERNOS #
####################################################
$IPT -P FORWARD DROP
$IPT -A FORWARD -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
$IPT -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPT -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
$IPT -A FORWARD -m state --state INVALID -j DROP
$IPT -A FORWARD -s x.0.0.0/8 -d $REDE_LAN -j ACCEPT
$IPT -A FORWARD -d x.0.0.0/8 -s $REDE_LAN -j ACCEPT
$IPT -A FORWARD -s $FTP -j ACCEPT
$IPT -A FORWARD -d $IP_WAN4 -j ACCEPT
$IPT -A FORWARD -s $ARQUIVO -j ACCEPT
$IPT -A FORWARD -d $IP_WAN3 -j ACCEPT
$IPT -A FORWARD -s ! 10.32.0.1 -p tcp -m multiport --dports 80,443 -o $IF_WAN2 -j DROP
$IPT -A FORWARD -s ! 10.32.0.1 -p tcp -m multiport --dports 80,443 -o $IF_WAN1 -j DROP
$IPT -A FORWARD -s $REDE_LAN -p icmp -j ACCEPT
$IPT -A FORWARD -s $REDE_LAN -p udp -m multiport --dports 53,67 -j ACCEPT
####################################################
# ENDERECOEXTERNOS #
####################################################
$IPT -A FORWARD -p tcp -d 200.x.0.0/16 -j ACCEPT # CONECTIVIDDE SOCIAL
$IPT -A FORWARD -p tcp -d 200.x.x.130 --dport 5077 -j ACCEPT #OI
$IPT -A FORWARD -p tcp -d 200.x.x.130 --dport 5099 -j ACCEPT #OI
$IPT -A FORWARD -p tcp -d 200.x.x.130 --dport 23 -j ACCEPT # OI
$IPT -A FORWARD -p tcp -d 161.x.x.239 --dport 443 -j ACCEPT # GDRAIS
###################
# TESTE VPN #
###################
$IPT -A FORWARD -p tcp -d 200.x.x.x --dport 1723 -j ACCEPT
#$IPT -A FORWARD -p udp --dport 1723 -j ACCEPT
$IPT -A FORWARD -p udp --dport 500 -j ACCEPT
$IPT -A FORWARD -p udp --dport 4500 -j ACCEPT
#$IPT -A FORWARD -p udp --dport 50 -j ACCEPT
###################
# FORWARD DOS REDIRECTIONAMENTOS
##################
$IPT -A FORWARD -i $IF_WAN2 -d $FTP -p tcp --dport 21 -j ACCEPT
$IPT -A FORWARD -i $IF_WAN2 -d $FTP -p tcp -m multiport --dports 20,21 -j ACCEPT
$IPT -A FORWARD -d $FTP -p tcp -m multiport --dports 20,21 -j ACCEPT
$IPT -A FORWARD -d $FTP -p tcp --dport 21 -j ACCEPT
$IPT -A FORWARD -i $IF_WAN2 -d $PDC -p tcp --dport 3389 -j ACCEPT
$IPT -A FORWARD -i $IF_WAN1 -d $CAMERAS -p tcp --dport 37777 -j ACCEPT
$IPT -A FORWARD -i $IF_WAN1 -d $CAMERAS -p tcp -m multiport --dports 37777,80 -j ACCEPT
$IPT -A FORWARD -d $ARQUIVO -p tcp --dport 10000 -j ACCEPT
$IPT -A FORWARD -d $MAILSRV -p tcp --dport 10000 -j ACCEPT
$IPT -A FORWARD -i $IF_DMZ -d $MAILHUB -p tcp --dport 22 -j ACCEPT
$IPT -A FORWARD -i $IF_DMZ -d $MAILSRV -p tcp -m multiport --dports 110,143,25,22 -j ACCEPT
#$IPT -A FORWARD -i $IF_DMZ -d $INTRANET -p udp --dport 53 -j ACCEPT
$IPT -A FORWARD -s $REDE_DMZ -j ACCEPT
$IPT -A FORWARD -i $IF_MPLS -j ACCEPT
#$IPT -A FORWARD -i $IF_WAN2 -d $INTRANET -p tcp --dport 53 -j ACCEPT
#$IPT -A FORWARD -i $IF_WAN2 -d $INTRANET -p udp --dport 53 -j ACCEPT
$IPT -A FORWARD -i $IF_WAN2 -d $MAILSRV -p tcp -m multiport --dports 110,25,143,80,993 -j ACCEPT
$IPT -A FORWARD -i $IF_WAN1 -d $CAMERAS -p tcp --dport 80 -j ACCEPT
$IPT -A FORWARD -i $IF_WAN1 -d $CAMERAS -p tcp --dport 37777 -j ACCEPT
$IPT -A FORWARD -i $IF_WAN2 -d $ARQUIVO -p tcp -m multiport --dports 20,21 -j ACCEPT
$IPT -A FORWARD -i $IF_LAN0 -d $INTRANET -p tcp --dport 80 -j ACCEPT
$IPT -A FORWARD -i $IF_LAN0 -d $REDE_DMZ -j ACCEPT
###LIBERACAO PORTAS SAIDA###
if [ -f $SAIDA_TCP ]; then
for i in `cat $SAIDA_TCP`; do
PORTA=`echo $i | cut -d ';' -f1`
$IPT -A FORWARD -p tcp --dport $PORTA -o $IF_WAN2 -j ACCEPT
$IPT -A FORWARD -p tcp --dport $PORTA -o $IF_WAN1 -j ACCEPT
done
fi
if [ -f $SAIDA_UDP ]; then
for i in `cat $SAIDA_UDP`; do
PORTA=`echo $i | cut -d ';' -f1`
$IPT -A FORWARD -p udp --dport $PORTA -o $IF_WAN2 -j ACCEPT
$IPT -A FORWARD -p udp --dport $PORTA -o $IF_WAN1 -j ACCEPT
done
fi
#liberacao voz contacta udp varias portas
#$IPT -A FORWARD -p udp --dport 3000:65000 -o $IF_WAN2 -j ACCEPT
#$IPT -A FORWARD -p udp --dport 3000:65000 -o $IF_WAN1 -j ACCEPT
#$IPT -A FORWARD -p tcp --dport 49152:65534 -o $IF_WAN2 -j ACCEPT
#$IPT -A FORWARD -p tcp --dport 20 -o $IF_WAN2 -j ACCEPT
#$IPT -A FORWARD -p tcp --dport 21 -o $IF_WAN2 -j ACCEPT
#########################################
# BLOQUEIO DO MSN
##########################################
$IPT -A FORWARD -p tcp --dport 6891:6901 -j DROP
$IPT -A FORWARD -p tcp --dport 1863 -j DROP
$IPT -A FORWARD -p udp --dport 1863 -j DROP
$IPT -A FORWARD -p tcp --dport 5190 -j DROP
$IPT -A FORWARD -p udp --dport 5190 -j DROP
echo "Iniciando tabela NAT"
########################
# NAT #
########################
$IPT -t nat -F
$IPT -t nat -X
$IPT -t nat -Z
########################
# FILTER: PREROUTING
########################
#######################
# Redirecionamentos #
#######################
$IPT -t nat -A PREROUTING -p tcp -m multiport --dports 20,21 -i $IF_WAN2 -j DNAT --to-destination $FTP
$IPT -t nat -A PREROUTING -d $IP_WAN2 -p tcp --dport 45521 -j DNAT --to-destination $PDC
$IPT -t nat -A PREROUTING -d $IP_WAN1 -p tcp --dport 45525 -j DNAT --to-destination $CAMERAS
$IPT -t nat -A PREROUTING -p tcp -m multiport --dports 20,21 -i $IF_WAN2 -j DNAT --to-destination $ARQUIVO
$IPT -t nat -A PREROUTING -p tcp -i $IF_WAN2 --dport 10001 -j DNAT --to-destination $ARQUIVO:10000
$IPT -t nat -A PREROUTING -p tcp -i $IF_WAN1 -m multiport --dports 20,21 -j DNAT --to-destination $FTP
$IPT -t nat -A PREROUTING -p tcp -i $IF_WAN2 --dport 10002 -j DNAT --to-destination $MAILSRV:10000
$IPT -t nat -A PREROUTING -p tcp -i $IF_WAN2 --dport 3389 -j DNAT --to-destination $PDC
$IPT -t nat -A PREROUTING -p tcp -d $IP_WAN3 -m multiport --dports 25,143,110,80,993 -j DNAT --to-destination $MAILSRV
#########################
# PROXY TRANSPARENTE - Primeira linha alterada por Diego para ao redirecionar trafego para o ADAPTTA
########################
$IPT -t nat -A PREROUTING -p tcp -d 200.x.x.x/16 -j ACCEPT
$IPT -t nat -A PREROUTING -p tcp -d 10.x.0.x -j ACCEPT
##############
# POSTROUTING
##############
# O IMPARCIAL ONLINE E OUTROS SERVICOS SAEM PELA EMBRATEL
# MPLS
$IPT -t nat -I POSTROUTING -d 192.168.x.x -j SNAT --to-source $IP_LAN
$IPT -t nat -I POSTROUTING -d 10.x.x.x4 -j SNAT --to-source $IP_LAN
$IPT -t nat -I POSTROUTING -d 192.168.x.x -j SNAT --to-source $IP_LAN
$IPT -t nat -I POSTROUTING -d 192.168.x.x -j SNAT --to-source $IP_LAN
$IPT -t nat -A POSTROUTING -s 192.168.x.x -d 192.168.x.x -j SNAT --to-source $IP_LAN
# SAIDA
$IPT -t nat -A POSTROUTING -s $REDE_DMZ -o $IF_WAN2 -j SNAT --to-source $IP_WAN3
$IPT -t nat -A POSTROUTING -o $IF_WAN2 -j SNAT --to-source $IP_WAN2
$IPT -t nat -A POSTROUTING -o $IF_WAN1 -j SNAT --to-source $IP_WAN1
$IPT -t nat -A POSTROUTING -o $IF_WAN2 -j SNAT --to-source $IP_WAN4
#########################
# ROTEAMENTO AVANCADO
#########################
# ROTAS
/opt/salyx/fw/./rotas.sh
/opt/salyx/fw/./rpfilter.sh
$IPT -t mangle -A PREROUTING -i $IF_LAN0 -d 192.168.x.x/24 -j ACCEPT
$IPT -t mangle -A PREROUTING -i $IF_LAN0 -d 192.168.x.x -j ACCEPT
$IPT -t mangle -A PREROUTING -i $IF_LAN0 -d 192.168.x.x -j ACCEPT
$IPT -t mangle -A PREROUTING -i $IF_DMZ -d ! 192.0.0.0/8 -j MARK --set-mark 0x3
#prioridade voip contacta
$IPT -t mangle -A OUTPUT -p udp --dport 4569 -j TOS --set-tos 0x10
$IPT -t mangle -A PREROUTING -p udp --dport 4569 -j TOS --set-tos 0x10
$IPT -t mangle -A OUTPUT -p tcp --dport 4569 -j TOS --set-tos 0x10
$IPT -t mangle -A PREROUTING -p tcp --dport 4569 -j TOS --set-tos 0x10
ip rule del table OI
ip route del table OI
ip rule add fwmark 0x3 table OI
ip route add default via 200.x.x.x dev eth3 table OI
ip route add default via 200.x.x.x dev eth3
ip route add default via 200.x.x.x dev eth1
# Rota ADD por Diego em 11/2009 para mailmanager.diariosassociados.com.br
ip rule add from all to 54.200.x.x.x8 lookup OI
#ip rule add from all to 189.16.241.131 lookup OI #voipcontacta
ip rule add from all to 65.200.x.x.x lookup OI #newseum
ip rule add from all to 187.6.64.5 lookup OI #ftpcorreioweb
ip route flush cache
# FIM
echo 16384 > /proc/sys/net/ipv4/neigh/default/gc_thresh1
echo 32768 > /proc/sys/net/ipv4/neigh/default/gc_thresh2
echo 65535 > /proc/sys/net/ipv4/neigh/default/gc_thresh3
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo "Ativando o IP Forwarding..."
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
# Protecao contra ICMP Broadcasting
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo "Pronto."
$IPT -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
echo "Pronto."
echo "Regras de firewall ativadas"