IPTABLES="/sbin/iptables"
IPT=$IPTABLES
ROUTE="/sbin/route"
DIR="/etc/firewall"
#
#----
# Regras gerais de tratamento de pacotes
#----
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t nat -X
$IPTABLES -X
$IPTABLES -F INPUT
$IPTABLES -F FORWARD
$IPTABLES -F OUTPUT
#
#----------
# Aceita todas as conexoes do loopback
#----------
$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A FORWARD -i lo -j ACCEPT
#
#----------
# Ping-of-Death, Syn-Flood, Port-Scanner
# Permissao de ping para as interfaces locais
#----------
$IPTABLES -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
$IPTABLES -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
$IPTABLES -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
$IPTABLES -A INPUT -p icmp -m limit --limit 1/s -j ACCEPT
#
#----------
# Aceita conexoes estabelecidades
#----------
$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
#
#----------
# LOG e DROP de pacotes fragmentados
#----------
$IPTABLES -A FORWARD -m state --state INVALID -j DROP
$IPTABLES -A INPUT -f -j LOG --log-prefix "Pacote INPUT fragmentado: "
$IPTABLES -A INPUT -f -j DROP
$IPTABLES -A FORWARD -f -j LOG --log-prefix "Pacote FORWARD fragmentado: "
$IPTABLES -A FORWARD -f -j DROP
#
#----------
# Declara IP dos Servidores
#----------
NS1="200.242.55.2"
NS2="10.0.0.2"
NS3="10.0.0.6"
#
#----------
# Declara redes utilizadas por este cache
#----------
PTP="172.20.0.0/28"
V01="200.242.55.0/27"
V02="200.242.55.32/28"
V03="200.242.55.48/30"
V04="200.242.55.52/30"
V05="200.242.55.56/29"
P01="192.168.60.0/24"
B01="192.168.70.0/24"
B02="192.168.71.0/24"
#
#----------
# Declara rotas para redes distantes
#----------
$ROUTE add -net $PTP gw $NS3
$ROUTE add -net $V02 gw $NS3
$ROUTE add -net $V03 gw $NS3
$ROUTE add -net $V04 gw $NS3
$ROUTE add -net $V05 gw $NS3
$ROUTE add -net $P01 gw $NS3
$ROUTE add -net $B01 gw $NS3
$ROUTE add -net $B02 gw $NS3
#
#---------
# EXECUTA QOS
#---------
/etc/firewall/qos/qos.sh
#
#---------
# MASCARAMENTO
#---------
$IPTABLES -t nat -A POSTROUTING -s $NS3 -j MASQUERADE
$IPTABLES -t nat -A POSTROUTING -s $P01 -j MASQUERADE
$IPTABLES -t nat -A POSTROUTING -s $B01 -j MASQUERADE
$IPTABLES -t nat -A POSTROUTING -s $B02 -j MASQUERADE