leogoss
(usa Ubuntu)
Enviado em 13/02/2012 - 15:55h
mas estando desabilitado o firewall nao deveria estar tudo para tudo?
quando tinha o kurumin coloquei no iptables isto:
no ubuntu eu acho que devo usar sudo ufw
firewall_start(){
# LIMPANDO AS TABELAS
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
#LIBERA LOOPBACK
iptables -A OUTPUT -p tcp --syn -s 127.0.0.1/255.0.0.0 -j ACCEPT
#Pacotes
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT #http
iptables -A INPUT -p tcp --dport 443 -j ACCEPT # https
iptables -A INPUT -p udp --dport 465 -j ACCEPT
iptables -A FORWARD -p TCP -s 192.168.0.0/23 --dport 25 -j ACCEPT
iptables -A FORWARD -p TCP -s 192.168.0.0/23 --dport 587 -j ACCEPT
iptables -A FORWARD -p TCP -s 192.168.0.0/23 --dport 110 -j ACCEPT
iptables -A FORWARD -p tcp --sport 25 -j ACCEPT
iptables -A FORWARD -p tcp --sport 587 -j ACCEPT
iptables -A FORWARD -p tcp --sport 110 -j ACCEPT
iptables -A INPUT -p tcp --dport 4199 -j ACCEPT # NFe
iptables -A INPUT -p tcp --dport 5959 -j ACCEPT # NFe
iptables -A INPUT -p tcp --dport 2006 -j ACCEPT # COBCaixa
iptables -A INPUT -p tcp --dport 1024 -j ACCEPT # Caixa
iptables -A INPUT -p tcp --dport 65535 -j ACCEPT # Caixa
iptables -A INPUT -p tcp --dport 3456 -j ACCEPT # Receitanet
iptables -A INPUT -p tcp --dport 5900 -j ACCEPT
iptables -A INPUT -p tcp --dport 5800 -j ACCEPT
iptables -A INPUT -p tcp --dport 3050 -j ACCEPT # Dafi-Sef
iptables -A INPUT -p tcp --dport 8017 -j ACCEPT # TED-Sef / DIEF
iptables -A INPUT -p tcp --dport 3456 -j ACCEPT # Dacon
iptables -A INPUT -p tcp --dport 3007 -j ACCEPT # Raisnet
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state INVALID -j DROP
iptables -A FORWARD -p tcp --dport 1863 -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state INVALID -j DROP
iptables -A OUTPUT -p tcp --dport 1863 -j ACCEPT
iptables -A OUTPUT -m multiport -p udp --dport ! 53,465 -j DROP
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
echo " * Loga tentativa de acesso a determinadas portas [ OK ] "
##Loga tentativa de acesso a determinadas portas
#iptables -A INPUT -p tcp --dport 21 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: ftp: "
#iptables -A INPUT -p tcp --dport 23 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: telnet: "
#iptables -A INPUT -p tcp --dport 25 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: smtp: "
#iptables -A INPUT -p tcp --dport 80 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: http: "
#iptables -A INPUT -p tcp --dport 110 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: pop3: "
#iptables -A INPUT -p udp --dport 111 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: rpc: "
#iptables -A INPUT -p tcp --dport 113 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: identd: "
#iptables -A INPUT -p tcp --dport 137:139 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: samba: "
#iptables -A INPUT -p udp --dport 137:139 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: samba: "
#iptables -A INPUT -p tcp --dport 161:162 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: snmp: "
#iptables -A INPUT -p tcp --dport 6667:6668 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: irc: "
#iptables -A INPUT -p tcp --dport 3128 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: squid: "
echo " * DAPI-SEF [ OK ] "
##Dapi-sef
iptables -A FORWARD -p tcp --dport 3050 -j ACCEPT
iptables -A INPUT -p tcp -s 192.168.0.0/23 --dport 3050 -j ACCEPT
iptables -A INPUT -p udp -s 192.168.0.0/23 --dport 3050 -j ACCEPT
echo " * TEDSEF [ OK ] "
##Liberando TEDSEF
iptables -t nat -A PREROUTING -s 192.168.0.0/23 -p tcp -d 200.199.34.41 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.199.34.41 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.1.0/24 -d 200.199.34.41 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.199.34.41 --dport 8017 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.199.34.41 --sport 8017 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.199.34.41 --dport 80 -j ACCEPT
echo " * Sintegra [ OK ] "
##Liberando Sintegra
iptables -t filter -A FORWARD -p tcp -s 192.168.0.0/23 --dport 8017 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.0.0/23 -p tcp -d 200.19.215.11 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.0.0/23 -p tcp -d 200.19.215.12 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/23 -d 200.19.215.11 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/23 -d 200.19.215.12 -j ACCEPT
echo " * ReceitaNet [ OK ] "
##ReceitaNET
iptables -t nat -A PREROUTING -s 192.168.0.0/23 -p tcp -d 161.148.185.130 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/23 -d 161.148.185.130 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.0.0/23 -d 161.148.185.130 --dport 3456 -j ACCEPT
echo " * Liberando Acesso Nota Fiscal Eletronica [ OK ] "
## Liberando acesso a NFE (Nota fiscal Eletronica)
iptables -t nat -I PREROUTING -s 192.168.0.0/23 -p tcp -d 200.189.133.249/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.189.133.249 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.189.133.249 --dport 4199:5656 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.189.133.249 --sport 4199:5656 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.189.133.249 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.0.0/23 -p tcp -d 200.189.133.247/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.189.133.247 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.189.133.247 --dport 4199:5656 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.189.133.247 --sport 4199:5656 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.189.133.247 --dport 80 -j ACCEPT
echo " * Sicoob [ OK ] "
##Programa Boleto sicoob
iptables -t nat -A PREROUTING -s 192.168.0.0/23 -p tcp -d 200.252.146.0/24 --dport 80 -j RETURN
echo " * Sefip / CNS [ OK ] "
##Sefip / CNS
iptables -t nat -A PREROUTING -p tcp -d 200.201.0.0/16 -j ACCEPT
iptables -A FORWARD -p tcp -d 200.201.0.0/16 -j ACCEPT
echo " * Caixa Economica [ OK ] "
## Caixa Economica
iptables -t nat -I PREROUTING -s 192.168.0.0/23 -p tcp -d 200.201.174.0/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.174.0/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.174.0/24 --dport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.174.0/24 --sport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.174.0/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.0.0/23 -p tcp -d 200.201.173.0/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.173.0/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.173.0/24 --dport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.173.0/24 --sport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.173.0/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.0.0/23 -p tcp -d 200.201.166.0/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.166.0/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.166.0/24 --dport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.166.0/24 --sport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.166.0/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.0.0/23 -p tcp -d 200.201.162.0/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.162.0/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.162.0/24 --dport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.162.0/24 --sport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.162.0/24 --dport 80 -j ACCEPT
echo " * Sefip [ OK ] "
##Sefip
iptables -t nat -I PREROUTING -s 192.168.0.0/23 -p tcp -d 200.201.173.68/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.173.68/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.173.68/24 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.173.68/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.0.0/23 -p tcp -d 200.201.166.200/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.166.200/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.166.200/24 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.166.200/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.0.0/23 -p tcp -d 200.201.174.204/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.174.204/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.174.204/24 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.174.204/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.0.0/23 -p tcp -d 200.201.174.207/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.174.207/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.174.207/24 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.0/23 -d 200.201.174.207/24 --dport 80 -j ACCEPT
echo " * Liberando Conectividade Social [ OK ] "
## Liberar Conectividade Social para todos
# liberando acesso a toda a rede 200.201 e pode liberar sites alem da Caixa.
iptables -t nat -A PREROUTING -p tcp -d 200.201.0.0/16 -j ACCEPT
iptables -A FORWARD -p tcp -d 200.201.0.0/16 -j ACCEPT
# PARA NAO FUGIREM DO PROXY
iptables -t nat -A PREROUTING -i eth1 -m multiport -p tcp --dport 80 -j REDIRECT --to-port 3128
#PORTAS PARA SAMBA
iptables -A INPUT -i eth1 -m multiport -p tcp --dport 53,135,139,445 -j ACCEPT
iptables -A INPUT -i eth1 -m multiport -p udp --dport 53,137,138 -j ACCEPT
# PRIORIZAR TRAFEGO HTTP, HTTPS
iptables -t mangle -A OUTPUT -o eth1 -p tcp --dport 80 -j TOS --set-tos 16
iptables -t mangle -A OUTPUT -o eth1 -p tcp --dport 443 -j TOS --set-tos 16
# Esta regra é o coração do firewall do Kurumin,
# ela bloqueia qualquer conexão que não tenha sido permitida acima, justamente por isso ela é a última da cadeia.
iptables -A INPUT -p tcp --syn -j DROP
echo "O Kurumin Firewall está sendo carregado..."
sleep 1
echo "Tudo pronto!"
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
;;
"stop")
firewall_stop
echo "O kurumin-firewall está sendo desativado"
sleep 2
echo "ok."
;;
"restart")
echo "O kurumin-firewall está sendo desativado"
sleep 1
echo "ok."
firewall_stop; firewall_start
;;
*)
iptables -L -n
esac