edumeira2009
(usa Debian)
Enviado em 29/12/2009 - 16:58h
meu firewall
#!/bin/bash
#####FIREWALL-PETRONET-INFORMATICA##########
firewall_start(){
# Abre para uma faixa de endereços da rede local
iptables -A INPUT -s 192.168.0.0/255.255.255.0 -j ACCEPT
# Abre uma Porta
iptables -A INPUT -p tcp --dport 5269 -j ACCEPT
iptables -A INPUT -p tcp --dport 8245 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 2222 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 8888 -j ACCEPT
#### CAMERAS
iptables -A INPUT -p tcp --dport 3550 -j ACCEPT
iptables -A INPUT -p tcp --dport 3350 -j ACCEPT
iptables -A INPUT -p tcp --dport 4550 -j ACCEPT
iptables -A INPUT -p tcp --dport 5550 -j ACCEPT
iptables -A INPUT -p tcp --dport 8081 -j ACCEPT
iptables -A INPUT -p tcp --dport 8000 -j ACCEPT
iptables -A INPUT -p tcp --dport 5222 -j ACCEPT
iptables -A INPUT -p tcp --dport 3389 -j ACCEPT
iptables -A INPUT -p tcp --dport 8217 -j ACCEPT
### TERMINAL SERVICE ###
iptables -A INPUT -p tcp --dport 3392 -j ACCEPT
iptables -A INPUT -p tcp --dport 3393 -j ACCEPT
iptables -A INPUT -p tcp --dport 3398 -j ACCEPT
iptables -A INPUT -p tcp --dport 3397 -j ACCEPT
iptables -A INPUT -p tcp --dport 3396 -j ACCEPT
iptables -A INPUT -p tcp --dport 491 -j ACCEPT
iptables -A INPUT -p tcp --dport 11111 -j ACCEPT
##GOGLOBAL###
iptables -A INPUT -p tcp --dport 9217 -j ACCEPT
iptables -A INPUT -p tcp --dport 9218 -j ACCEPT
iptables -A INPUT -p tcp --dport 7057 -j ACCEPT
iptables -A INPUT -p tcp --dport 7058 -j ACCEPT
iptables -A INPUT -p tcp --dport 3391 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 2038 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 2038 -j DNAT --to-destination 192.168.0.27:2038
# Ignora Pings
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
# Protege contra IP Spoofing
echo "1" > /proc/sys/net/ipv4/conf/default/rp_filter
# Protege contra synflood
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
# Protege contra ICMP Broadcasting
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# Protege contra Portscanners, ping of death, ataques DoS, etc.
iptables -A INPUT -m state --state INVALID -j DROP
# Regra para programas graficos funcionarem
iptables -A INPUT -i lo -j ACCEPT
######################REDIRECIONAMENTOS##########################
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 5269 -j DNAT --to 192.168.0.253
iptables -t nat -A POSTROUTING -d 192.168.0.253 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 5269 -j DNAT --to 192.168.0.253
iptables -t nat -A POSTROUTING -d 192.168.0.253 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 8245 -j DNAT --to 192.168.0.21
iptables -t nat -A POSTROUTING -d 192.168.0.21 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 8245 -j DNAT --to 192.168.0.21
iptables -t nat -A POSTROUTING -d 192.168.0.21 -j SNAT --to 192.168.0.1
###CAMERAS###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 8081 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 8081 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
###CAMERA###-1
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 3350 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3350 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 3550 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3550 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
###CAMERA###-2
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 4550 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 4550 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
###CAMERA###-3
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 5550 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 5550 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
###CAMERA###-4
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 6550 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 6550 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
###MARCIO###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3392 -j DNAT --to 192.168.0.19
iptables -t nat -A POSTROUTING -d 192.168.0.19 -j SNAT --to 192.168.0.1
###LEVY###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3393 -j DNAT --to 192.168.0.25
iptables -t nat -A POSTROUTING -d 192.168.0.25 -j SNAT --to 192.168.0.1
###FABIO###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3398 -j DNAT --to 192.168.0.36
iptables -t nat -A POSTROUTING -d 192.168.0.36 -j SNAT --to 192.168.0.1
###PEDRO###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3397 -j DNAT --to 192.168.0.171
iptables -t nat -A POSTROUTING -d 192.168.0.171 -j SNAT --to 192.168.0.1
###GHILHERME###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3396 -j DNAT --to 192.168.0.168
iptables -t nat -A POSTROUTING -d 192.168.0.168 -j SNAT --to 192.168.0.1
###CHAT-INTERNO###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 9090 -j DNAT --to 192.168.0.253
iptables -t nat -A POSTROUTING -d 192.168.0.253 -j SNAT --to 192.168.0.1
###CHAT-INTERNO-USER###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 5222 -j DNAT --to 192.168.0.253
iptables -t nat -A POSTROUTING -d 192.168.0.253 -j SNAT --to 192.168.0.1
###TERMINAL SERVICE Servidor antigo###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3389 -j DNAT --to 192.168.0.170
iptables -t nat -A POSTROUTING -d 192.168.0.170 -j SNAT --to 192.168.0.1
###TERMINAL SERVICE INTEGRA###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3390 -j DNAT --to 192.168.0.253
iptables -t nat -A POSTROUTING -d 192.168.0.253 -j SNAT --to 192.168.0.1
###PORTA 8217###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 8217 -j DNAT --to 192.168.0.253
iptables -t nat -A POSTROUTING -d 192.168.0.253 -j SNAT --to 192.168.0.1
###PORTA 8217-INTERNA###
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 8217 -j DNAT --to 192.168.0.253
iptables -t nat -A POSTROUTING -d 192.168.0.253 -j SNAT --to 192.168.0.1
###############MAQUINA-1###########################
###GO-GLOBAL####
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 9217 -j DNAT --to 192.168.0.166
iptables -t nat -A POSTROUTING -d 192.168.0.166 -j SNAT --to 192.168.0.1
###GO-GLOBAL-PORTA7057####
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 7057 -j DNAT --to 192.168.0.166
iptables -t nat -A POSTROUTING -d 192.168.0.166 -j SNAT --to 192.168.0.1
###############MAQUINA-2###########################
###GO-GLOBAL####
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 9218 -j DNAT --to 192.168.0.58
iptables -t nat -A POSTROUTING -d 192.168.0.58 -j SNAT --to 192.168.0.1
###GO-GLOBAL-PORTA7057####
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 7058 -j DNAT --to 192.168.0.58
iptables -t nat -A POSTROUTING -d 192.168.0.58 -j SNAT --to 192.168.0.1
#########################GO_GLOBAL_INTERNO#############################################
###############MAQUINA-1###########################
###GO-GLOBAL####
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 9217 -j DNAT --to 192.168.0.166
iptables -t nat -A POSTROUTING -d 192.168.0.166 -j SNAT --to 192.168.0.1
###GO-GLOBAL-PORTA7057####
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 7057 -j DNAT --to 192.168.0.166
iptables -t nat -A POSTROUTING -d 192.168.0.166 -j SNAT --to 192.168.0.1
###############MAQUINA-2###########################
###GO-GLOBAL####
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 9218 -j DNAT --to 192.168.0.58
iptables -t nat -A POSTROUTING -d 192.168.0.58 -j SNAT --to 192.168.0.1
###GO-GLOBAL-PORTA7057####
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 7058 -j DNAT --to 192.168.0.58
iptables -t nat -A POSTROUTING -d 192.168.0.58 -j SNAT --to 192.168.0.1
###Mauqina cameras-nova###
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3391 -j DNAT --to 192.168.0.254
iptables -t nat -A POSTROUTING -d 192.168.0.254 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 8888 -j DNAT --to 192.168.0.59
iptables -t nat -A POSTROUTING -d 192.168.0.59 -j SNAT --to 192.168.0.1
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 8888 -j DNAT --to 192.168.0.59
iptables -t nat -A POSTROUTING -d 192.168.0.59 -j SNAT --to 192.168.0.1
#####################FIM-REDIRECIONAMENTOS############################
###BLOQUEA TUDO QUE NAO ESTEJA DESCRITO ACIMA###
iptables -A INPUT -p tcp --syn -j DROP
echo "O Firewall esta sendo carregado..."
sleep 1
#echo "OK"
sleep 1
}
firewall_stop(){
iptables -F
iptables -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
}
case "$1" in
"start")
firewall_start
echo "O Firewall esta sendo ativado"
;;
"stop")
firewall_stop
echo "O Firewall esta sendo desativado"
sleep 2
#echo "OK."
;;
"restart")
echo "O Firewall esta sendo ativado"
sleep 1
#echo "OK."
firewall_stop; firewall_start
;;
*)
iptables -L -n
esac