Enviado em 21/10/2015 - 10:54h
Olá companheiros.
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
#Rede Local
auto eth0
iface eth0 inet static
address 192.168.XXX.254
netmask 255.255.255.0
#Interface WAN 1 - GVT
auto eth1
iface eth1 inet static
address 10.XXX.XXX.10
netmask 255.255.255.0
gateway 10.XXX.XXX.1
#Interface WAN 2 - NET
auto eth2
iface eth2 inet static
address 192.XXX.XXX.9
netmask 255.255.255.0
gateway 192.XXX.XXX.1
#Interface WAN 3 - OI VELOX (IP 1)
auto eth3
iface eth3 inet static
address XXX.XXX.XXX.101
netmask 255.255.255.240
gateway XXX.XXX.XXX.100
#Interface WAN 3 - OI VELOX (IP 2)
auto eth3:1
iface eth3:1 inet static
address XXX.XXX.XXX.102
netmask 255.255.255.240
gateway XXX.XXX.XXX.100
#Interface WAN 3 - OI VELOX (IP 3)
auto eth3:2
iface eth3:2 inet static
address XXX.XXX.XXX.103
netmask 255.255.255.240
gateway XXX.XXX.XXX.100
#Interface WAN 3 - OI VELOX (IP 4)
auto eth3:3
iface eth3:3 inet static
address XXX.XXX.XXX.104
netmask 255.255.255.240
gateway XXX.XXX.XXX.100
#Interface WAN 3 - OI VELOX (IP 5)
auto eth3:4
iface eth3:4 inet static
address XXX.XXX.XXX.105
netmask 255.255.255.240
gateway XXX.XXX.XXX.100
#!/bin/sh -e
echo "=========================================================="
echo "| FIREWALL |"
echo "=========================================================="
echo " "
echo " "
echo " "
### Habilitando modulos do ipcontrack/iptables
/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_mangle
/sbin/modprobe iptable_nat
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_limit
/sbin/modprobe ipt_state
/sbin/modprobe ipt_REDIRECT
/sbin/modprobe ipt_owner
/sbin/modprobe ipt_REJECT
/sbin/modprobe ipt_MASQUERADE
echo "Habilitando Módulos ....................................[ OK ]"
echo " "
###LIMPANDO REGRAS
iptables -F
iptables -F INPUT
iptables -F OUTPUT
iptables -F POSTROUTING -t nat
iptables -F PREROUTING -t nat
iptables -t mangle -F
iptables -t mangle -X
echo "Limpando todas as regras ...............................[ OK ]"
echo " "
### Habilitando comunicação entre interfaces
echo 1 > /proc/sys/net/ipv4/ip_forward
echo "Habilitando comunicação entre interfaces ...............[ OK ]"
echo " "
### Protecao contra ataques de syn flood (inicio da conexao TCP). Tenta conter ataques de DoS.
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo "Setando protecao anti_synflood .........................[ OK ]"
echo " "
### Protecao contra port scanners ocultos
iptables -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
echo "Setando protecao port scanners .........................[ OK ]"
echo " "
### Bloqueando tracertroute
iptables -A INPUT -p udp -s 0/0 -i eth1 --dport 33435:33525 -j DROP
iptables -A INPUT -p udp -s 0/0 -i eth2 --dport 33435:33525 -j DROP
iptables -A INPUT -p udp -s 0/0 -i eth3 --dport 33435:33525 -j DROP
echo "Bloqueando tracert/traceroute ..........................[ OK ]"
echo " "
#Protecoes contra ataques
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A OUTPUT -p tcp ! --tcp-flags SYN,RST,ACK SYN -m state --state NEW -j DROP
echo "Setando protecao contra ataques ........................[ OK ]"
echo " "
#Ping da morte
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
echo "Setando protecao contra ping da morte ..................[ OK ]"
echo " "
#Protecao contra Syn-floods
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
echo "Setando protecao anti_synflood .........................[ OK ]"
echo " "
### Dizendo quais sockets são válidos para conexão
iptables -A INPUT -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
iptables -A INPUT -m state --state INVALID -j DROP
echo "Setando regras para INPUT ..............................[ OK ]"
echo " "
#Liberando acessos por SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
echo "Liberando Acessos por SSH ..............................[ OK ]"
echo " "
# Liberando Porta 110 (pop-3)
iptables -A FORWARD -s 192.168.116.0/24 -p tcp --dport 110 -j ACCEPT
echo "Liberando Porta POP-3 ..................................[ OK ]"
echo " "
# Liberando Porta 995 (spop-3)
iptables -A FORWARD -s 192.168.116.0/24 -p tcp --dport 995 -j ACCEPT
echo "Liberando Porta SPOP-3 .................................[ OK ]"
echo " "
# Liberando Porta 25 (smtp)
iptables -A FORWARD -s 192.168.116.0/24 -p tcp --dport 25 -j ACCEPT
echo "Liberando Porta SMTP ...................................[ OK ]"
echo " "
# Liberando Porta 465 (smtp-s)
iptables -A FORWARD -s 192.168.116.0/24 -p tcp --dport 465 -j ACCEPT
echo "Liberando Porta SMTP-S .................................[ OK ]"
echo " "
# Liberando Porta 22 (ssh)
iptables -A FORWARD -s 0/0 -p tcp --dport 22 -j ACCEPT
echo "Liberando Porta SSH ....................................[ OK ]"
echo " "
# Liberando porta 53 (DNS)
iptables -A FORWARD -s 192.168.X.X/24 -p tcp --dport 53 -j ACCEPT
iptables -A FORWARD -s 192.168.X.X/24 -p udp --dport 53 -j ACCEPT
echo "Liberando Porta do DNS .................................[ OK ]"
echo " "
#Liberando acessos para as portas web
iptables -t filter -A FORWARD -p tcp --dport 80 -j ACCEPT
iptables -t filter -A FORWARD -p tcp --dport 443 -j ACCEPT
iptables -t filter -A FORWARD -p tcp --dport 22 -j ACCEPT
echo "Liberando Acessos FORWARD ..............................[ OK ]"
echo " "
#Redirecionamento para o servidor web
iptables -A PREROUTING -t nat -p tcp -d XXX.XXX.XXX.101 -m multiport --dport 1:65535 -j DNAT --to-destination 192.168.XXX.9
echo "Redirecionando acessos web .............................[ OK ]"
#echo " "
###Liberando acesso do Servidor Proxy
iptables -t nat -A PREROUTING -i eth0 -s 192.168.XXX.5 -p tcp -m multiport --dport 1:65535 -j ACCEPT
echo "Liberando acesso sem PROXY .............................[ OK ]"
echo " "
#Mascaramento de IP - libera internet p fora da rede do ciodes
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 192.168.XXX.9 -o eth3 -j SNAT --to-source XXX.XXX.XXX.101
echo "Ativando mascaramento de IP ............................[ OK ]"
echo " "
#Regras do IP Route e Marcação de Pacotes
ip route add 192.168.XXX.9/32 dev eth3 table oi
ip route add default dev eth3 via XXX.XXX.XXX.100 table oi
ip route flush cached
iptables -t mangle -F
iptables -t mangle -X
iptables -t mangle -A POSTROUTING -p tcp --sport 80 -s 192.168.XXX.9/32 -j MARK --set-mark 1
iptables -t mangle -A PREROUTING -p tcp --sport 80 -s 192.168.XXX.9/32 -j MARK --set-mark 1
iptables -t mangle -A OUTPUT -p tcp --sport 80 -s 192.168.XXX.9/32 -j MARK --set-mark 1
iptables -t mangle -A FORWARD -p tcp --sport 80 -s 192.168.XXX.9/32 -j MARK --set-mark 1
ip rule add fwmark 1 lookup oi
ip route flush cached
echo " "
echo "-----------=========== FIREWALL ATIVADO ===========-----------"
echo " "
echo " "
exit 0