francofalleiros
(usa CentOS)
Enviado em 05/04/2013 - 15:21h
Boa tarde André..
Ok... Veja o firewall:
=======================================================================================================
echo "Iniciando Firewall"
#--------------------------------------------------------------------------------------------------------------------------------------
# Libera Portas de saida
PORT_TCP="20,21,25,53,80,84,106,110,443,445,8080"
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"
#--------------------------------------------------------------------------------------------------------------------------------------
# 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
iptables -A INPUT -p tcp --destination-port 22 -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 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
#--------------------------------------------------------------------------------------------------------------------------------------
#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 -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.0/24 -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 3389 -j DNAT --to-destination 192.168.1.250
#iptables -t nat -A PREROUTING -i eth0 -s 0.0.0.0/0.0.0.0 -p tcp --dport 3390 -j DNAT --to-destination 192.168.1.251:3389
###############################################################################################################
#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!!!"
=======================================================================================================
Este é o resultado do Route -n :
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1004 0 0 eth2
10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 eth2
0.0.0.0 192.168.1.2 0.0.0.0 UG 0 0 0 eth0
Ao aguardo,