francofalleiros
(usa CentOS)
Enviado em 01/07/2013 - 19:09h
Segue Firewall...
echo "Iniciando Firewall"
#--------------------------------------------------------------------------------------------------------------------------------------
# Libera Portas de saida
PORT_TCP="20,21,25,53,80,84,106,110,443,445,8080,20580"
PORT_REMOTE="22,3389,3390,5500,5900,33899"
PORT_UDP="53,447"
MSNPORT_TCP="1723,47,1863,6891,8017,5000,3456,8443"
PORTS="587,2631,465,8800,995"
#--------------------------------------------------------------------------------------------------------------------------------------
# Carrega os Modulos
/sbin/modprobe iptable_nat
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_REJECT
/sbin/modprobe ipt_MASQUERADE
#--------------------------------------------------------------------------------------------------------------------------------------
# Ativa o Roteamento
echo 1 > /proc/sys/net/ipv4/ip_forward
#--------------------------------------------------------------------------------------------------------------------------------------
# Limpa as tabelas
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
#--------------------------------------------------------------------------------------------------------------------------------------
# Tabela FILTER - Seta Politica de DROP como padrão
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
#--------------------------------------------------------------------------------------------------------------------------------------
# Libera loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -s 127.0.0.1/255.255.255.0 -j ACCEPT
#-------------------------------------------------------------------------------
# Libera conexao de entrada no linux vindo da rede interna
iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -j ACCEPT
#--------------------------------------------------------------------------------------------------------------------------------------
# Aceita pacote ICMP interno
iptables -A INPUT -p ICMP -s 192.168.0.0/24 -m state --state NEW -j ACCEPT
#--------------------------------------------------------------------------------------------------------------------------------------
# Libera entrada SSH de qualquer origem e Administracao via webmim
iptables -A INPUT -p tcp --destination-port 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 10000 -j ACCEPT
#--------------------------------------------------------------------------------------------------------------------------------------
# Regra para novas conexoes e estabelecidas
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#--------------------------------------------------------------------------------------------------------------------------------------
# Libera Forward da portas udp e tcp usando as variaveis
iptables -A FORWARD -i eth1 -d 0.0.0.0/0.0.0.0 -m multiport -p tcp --port $PORT_TCP -j ACCEPT
iptables -A FORWARD -i eth1 -d 0.0.0.0/0.0.0.0 -m multiport -p udp --port $PORT_UDP -j ACCEPT
iptables -A FORWARD -i eth1 -d 0.0.0.0/0.0.0.0 -m multiport -p tcp --port $PORT_REMOTE -j ACCEPT
iptables -A FORWARD -i eth1 -d 0.0.0.0/0.0.0.0 -m multiport -p tcp --port $MSNPORT_TCP -j ACCEPT
iptables -A FORWARD -i eth1 -d 0.0.0.0/0.0.0.0 -m multiport -p tcp --port $PORTS -j ACCEPT
#--------------------------------------------------------------------------------------------------------------------------------------
# Ativa mascaramento de saída (somente portas permitidas) variaveis PORT_TCP E MSNPORT_TCP
iptables -t nat -A POSTROUTING -o eth0 -m multiport -p tcp --port $PORT_TCP -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -m multiport -p udp --port $PORT_UDP -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -m multiport -p tcp --port $PORT_REMOTE -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -m multiport -p tcp --port $MSNPORT_TCP -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -m multiport -p tcp --port $PORTS -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -p icmp -j MASQUERADE
#--------------------------------------------------------------------------------------------------------------------------------------
#START DMZ
# Forward traffic between DMZ and LAN
iptables -A FORWARD -i eth1 -o eth2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth2 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Forward traffic between DMZ and WAN
iptables -A FORWARD -i eth2 -o eth0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth0 -o eth2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
#Route incoming HTTP port 80 traffic to DMZ Server
#iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8080 -j DNAT --to-destination 10.0.0.5:8080
#--------------------------------------------------------------------------------------------------------------------------------------
# Permitir que hosts internos acessem a consulta dos consorciados
iptables -t nat -I POSTROUTING -p tcp --dport 80 -d 10.0.0.5 -j MASQUERADE
iptables -I FORWARD -d 10.0.0.5 -j ACCEPT
iptables -I FORWARD -s 10.0.0.5 -j ACCEPT
#-------------------------------------------------------------------------------------------------------------------------------------
#LIBERAÇÃO DE PORTAS - SUPORTE REMOTO
#iptables -A FORWARD -i eth1 -d 0.0.0.0/0.0.0.0 -p tcp --dport 8001:9004 -j ACCEPT
#iptables -t nat -A POSTROUTING -o eth0 -p tcp --dport 8001:9004 -j MASQUERADE
#--------------------------------------------------------------------------------------------------------------------------------------
# LIBERAÇÃO PARA CONECTIVIDADE SOCIAL -- Trafego sem proxy
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.201.173.68 --dport 80 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.201.173.68 --dport 2631 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.201.174.204 --dport 80 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.201.174.204 --dport 2631 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.201.166.200 --dport 80 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.201.166.200 --dport 2631 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.201.166.240 --dport 80 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.201.166.240 --dport 2631 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.234.196.0/24 --dport 80 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.234.196.0/24 --dport 8017 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.201.166.106 --dport 80 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 200.247.125.225 --dport 8800 -j ACCEPT #Nexxera Caixa
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 65.221.13.140 --dport 80 -j ACCEPT #F-SECURE
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 65.221.13.141 --dport 80 -j ACCEPT #F-SECURE
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 65.221.13.143 --dport 80 -j ACCEPT #F-SECURE
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 65.221.13.145 --dport 80 -j ACCEPT #F-SECURE
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 85.214.17.195 --dport 80 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -p tcp -d 69.163.195.210 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 85.214.17.195 -j ACCEPT #LIVEZILLA
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 69.163.195.210 -j ACCEPT #LIVEZILLA
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 65.221.13.140 -j ACCEPT #F-SECURE
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 65.221.13.141 -j ACCEPT #F-SECURE
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 65.221.13.143 -j ACCEPT #F-SECURE
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 65.221.13.145 -j ACCEPT #F-SECURE
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 200.247.125.225 -j ACCEPT #Nexxera caixa
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 200.201.174.204 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 200.201.0.0/16 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 200.201.166.200 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 200.201.166.240 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 200.234.196.0/24 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d 65.55.16.0/24 -j ACCEPT
#--------------------------------------------------------------------------------------------------------------------------------------
# LIBERA MAQUINAS COM ACESSO DIRETO SEM PROXY
iptables -t nat -A PREROUTING -s 192.168.0.56 -d 0.0.0.0/0.0.0.0 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.0.33 -d 0.0.0.0/0.0.0.0 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.0.42 -d 0.0.0.0/0.0.0.0 -j ACCEPT
#--------------------------------------------------------------------------------------------------------------------------------------
# FORÇA O USO DE PROXY
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
#--------------------------------------------------------------------------------------------------------------------------------------
# Redireciona portas para outros servidores
iptables -t nat -A PREROUTING -i eth0 -s 0.0.0.0/0.0.0.0 -p tcp --dport 33898 -j DNAT --to-destination 192.168.0.252:3389
iptables -t nat -A PREROUTING -i eth0 -s 0.0.0.0/0.0.0.0 -p tcp --dport 80 -j DNAT --to-destination 10.0.0.5:80
#iptables -t nat -A OUTPUT -d xxxxxxx -s 0.0.0.0/0.0.0.0 -p tcp --dport 80 -j DNAT --to-destination 10.0.0.5:80
#iptables -t nat -A PREROUTING -d xxxxxxxxx -s 0.0.0.0/0.0.0.0 -p tcp --dport 80 -j DNAT --to-destination 10.0.0.5:80
###############################################################################################################
#Libera a vpn
#iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 1723 -j DNAT --to-destination 192.168.1.251:1723
#iptables -t nat -A PREROUTING -p gre -j DNAT --to 192.168.1.251
#iptables -t nat -A PREROUTING -p 47 -i eth0 -j DNAT --to-destination 192.168.1.251
#iptables -A FORWARD -s 0.0.0.0/0.0.0.0 -o eth0 -j ACCEPT
#iptables -A FORWARD -i eth0 -s 0/0 -d 192.168.1.251 -p 47 -j ACCEPT
#iptables -A FORWARD -i eth0 -s 0/0 -d 192.168.1.251 -p tcp -m tcp --dport 1723 -j ACCEPT
#iptables -t nat -A POSTROUTING -s 0.0.0.0/0.0.0.0 -o eth0 -j MASQUERADE
#################################################################################################################
# Protege nosso servidor contra synflood
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
iptables -A FORWARD -p tcp --syn -m limit --limit 2/s -j ACCEPT
#--------------------------------------------------------------------------------------------------------------------------------------
# Proteção contra ping da morte
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j DROP
iptables -A INPUT -p ICMP -s 0/0 -m state --state NEW -j DROP
#--------------------------------------------------------------------------------------------------------------------------------------
# Protege conta ICMP Broadcasting
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
#--------------------------------------------------------------------------------------------------------------------------------------
# Bloqueio Ping
echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
#--------------------------------------------------------------------------------------------------------------------------------------
# Se nao entrar em nenhuma regra acima rejeita tudo!
iptables -A INPUT -p tcp --syn -j DROP
#--------------------------------------------------------------------------------------------------------------------------------------
echo "Firewall Iniciado com Sucesso!!!"