Lucas Peregrino
(usa Debian)
Enviado em 27/06/2015 - 20:46h
Boa noite estou procurando sujestão para meu firewall n e mais perfeito n mais gostaria de dar uma melhorada nele.
#!/bin/bash
### BEGIN INIT INFO
# Provides: firewall
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
#digite
net=eth1
rede=eth0
ip_rede=192.168.4.0/24
servidor=(192.168.4.254 192.168.4.253 192.168.4.252)
lista="/etc/squid3/lists/ip"
PATH=/bin:/usr/bin:/sbin:/usr/sbin
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Starting Firewall execution" "IPTABLES"
log_end_msg $?
## Ativa Modulos
# -------------------------------------------------------
modprobe iptable_filter
modprobe iptable_nat
modprobe iptable_mangle
modprobe ipt_LOG
modprobe ipt_REDIRECT
modprobe ipt_MASQUERADE
# Configurando a Protecao anti-spoofing
for spoofing in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo "1" > $spoofing
done
# Impedimos que um atacante possa maliciosamente alterar alguma rota
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
# Utilizado em diversos ataques, isso possibilita que o atacante determine o "caminho" que seu
# pacote vai percorrer (roteadores) ate seu destino. Junto com spoof, isso se torna muito perigoso.
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
# Protecao contra responses bogus
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
# Protecao contra ataques de syn flood (inicio da conexao TCP). Tenta conter ataques de DoS.
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
# Finalmente: Habilitando o trafego IP, entre as Interfaces de rede
echo "1" > /proc/sys/net/ipv4/ip_forward
# Definindo o DROP
# -------------------------------------------------------
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
## ACCEPT (libera) pacotes de retorno da internet
# -------------------------------------------------------
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
## Abre para a interface de loopback.
# -------------------------------------------------------
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp --syn -s 127.0.0.1/24 -j ACCEPT
## Mascaramento de rede para acesso externo
# -------------------------------------------------------
iptables -t nat -A POSTROUTING -s $ip_rede -j MASQUERADE
## Redirecionamento porta 80 para 3128
# -------------------------------------------------------
iptables -t nat -A PREROUTING -s ${servidor[0]} -p tcp --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination ${servidor[0]}:3128
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3128
## Libera as portas do samba para Rede.
# -------------------------------------------------------
#TCP
#iptables -A FORWARD -s $ip_rede -p tcp --dport 137 -j ACCEPT
#iptables -A FORWARD -s $ip_rede -p tcp --dport 138 -j ACCEPT
#iptables -A FORWARD -s $ip_rede -p tcp --dport 139 -j ACCEPT
#iptables -A FORWARD -s $ip_rede -p tcp --dport 445 -j ACCEPT
#UDP
#iptables -A FORWARD -s $ip_rede -p udp --dport 137 -j ACCEPT
#iptables -A FORWARD -s $ip_rede -p udp --dport 138 -j ACCEPT
#iptables -A FORWARD -s $ip_rede -p udp --dport 139 -j ACCEPT
#iptables -A FORWARD -s $ip_rede -p udp --dport 445 -j ACCEPT
# Libera DHCP
# -------------------------------------------------------
iptables -A INPUT -s $ip_rede -p udp --sport 68 --dport 67 -j ACCEPT
# Libera DNS
# -------------------------------------------------------
iptables -A INPUT -s $ip_rede -p udp --dport 53 -j ACCEPT
# Libera HTTP e HTTPS
# -------------------------------------------------------
iptables -A INPUT -s $ip_rede -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -s $ip_rede -p tcp --dport 443 -j ACCEPT
# Libera SQUID
# -------------------------------------------------------
iptables -A INPUT -s $ip_rede -p tcp --dport 3128 -j ACCEPT
# Libera Apache 2
# -------------------------------------------------------
iptables -A FORWARD -s $ip_rede -p tcp --dport 8089 -j ACCEPT
iptables -A INPUT -i $net -p tcp --dport 8089 -j ACCEPT
# Libera PROFTPD
# -------------------------------------------------------
#iptables -A INPUT -s ${servidor[0]} -p tcp --dport 2189 -j ACCEPT
#iptables -A INPUT -s ${servidor[0]} -p tcp -m multiport --dports 21899:21900 -j ACCEPT
# Libera Spark
# -------------------------------------------------------
#iptables -A FORWARD -s $ip_rede -p tcp --dport 5222 -j ACCEPT
#iptables -A FORWARD -s $ip_rede -p tcp --dport 9090 -j ACCEPT
#iptables -A INPUT -i $net -p tcp --dport 5222 -j ACCEPT
#iptables -A INPUT -i $net -p tcp --dport 9090 -j ACCEPT
# Libera POP e SMTP
# -------------------------------------------------------
#25-110
iptables -A INPUT -s $ip_rede -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -s $ip_rede -p tcp --dport 110 -j ACCEPT
#465-587-995
iptables -A INPUT -s $ip_rede -p tcp --dport 465 -j ACCEPT
iptables -A INPUT -s $ip_rede -p tcp --dport 587 -j ACCEPT
iptables -A INPUT -s $ip_rede -p tcp --dport 995 -j ACCEPT
# Libera IMAP
# -------------------------------------------------------
#143-993
iptables -A INPUT -s $ip_rede -p tcp --dport 143 -j ACCEPT
iptables -A INPUT -s $ip_rede -p tcp --dport 993 -j ACCEPT
## Liberando SSH Servinet (porta 22)
# -------------------------------------------------------
iptables -A INPUT -i $net -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -s $ip_rede -p tcp --dport 22 -j ACCEPT
## Liberando NXSERVER (porta 4000)
# -------------------------------------------------------
iptables -A INPUT -i $net -p tcp --dport 4000 -j ACCEPT
iptables -A INPUT -s $ip_rede -p tcp --dport 4000 -j ACCEPT
# iptables -t nat -A PREROUTING -p tcp --dport 4000 -i $net -j DNAT --to ${servidor[1]}:4000
## Libera Terminal Server
# -------------------------------------------------------
# iptables -A INPUT -i $net -p tcp --dport 3389 -j ACCEPT
# iptables -A INPUT -s $ip_rede -p tcp --dport 3389 -j ACCEPT
# iptables -t nat -A PREROUTING -p tcp --dport 3389 -i $net -j DNAT --to ${servidor[2]}:3389
## Libera Camera
# -------------------------------------------------------
#iptables -A INPUT -i $net -p tcp --dport 3180 -j ACCEPT
#iptables -A INPUT -s $ip_rede -p tcp --dport 3180 -j ACCEPT
#iptables -t nat -A PREROUTING -p tcp --dport 3180 -i $net -j DNAT --to 192.168.2.45:3180
# Libera VPN
# -------------------------------------------------------
#iptables -A INPUT -i tun+ -j ACCEPT
#iptables -A FORWARD -i tun+ -j ACCEPT
## Libera Ares
# -------------------------------------------------------
#iptables -A INPUT -s $ip_rede -p tcp --dport 39093 -j ACCEPT
#iptables -A FORWARD -s $ip_rede -p tcp --dport 5800 -j ACCEPT
## Libera Azureus
# -------------------------------------------------------
#iptables -A INPUT -s $ip_rede -p tcp --dport 25390 -j ACCEPT
## libera VNC
# -------------------------------------------------------
#iptables -A INPUT -s $ip_rede -p tcp --dport 5900 -j ACCEPT
#iptables -A INPUT -s $ip_rede -p tcp --dport 5800 -j ACCEPT
## Libera Webmin
# -------------------------------------------------------
#iptables -A INPUT -s $ip_rede -p tcp --dport 332 -j ACCEPT
#iptables -A INPUT -i $net -p tcp --dport 332 -j ACCEPT
# Libera ntpdate (NTP)
# -------------------------------------------------------
iptables -A INPUT -s $ip_rede -p udp --sport 123 -j ACCEPT
# Libera Firebird
# -------------------------------------------------------
#iptables -A INPUT -s $ip_rede -p tcp --dport 3054 -j ACCEPT
#iptables -A INPUT -s $ip_rede -p tcp --dport 5787 -j ACCEPT
# Libera MySQL
# -------------------------------------------------------
#iptables -A INPUT -s $ip_rede -p tcp --dport 3306 -j ACCEPT
#iptables -A INPUT -s $ip_rede -p tcp --dport 3310 -j ACCEPT
## Sintegra
# -------------------------------------------------------
iptables -A INPUT -s $ip_rede -p tcp --dport 8017 -j ACCEPT
## ReceitaNET
# -------------------------------------------------------
iptables -A INPUT -s $ip_rede -p tcp --dport 3456 -j ACCEPT
## Dapi-sef
# -------------------------------------------------------
iptables -A INPUT -s $ip_rede -p tcp --dport 3050 -j ACCEPT
## Liberando acesso a NFE (Nota fiscal Eletronica)
# -------------------------------------------------------
iptables -A INPUT -s $ip_rede -p tcp --dport 4199 -j ACCEPT # NFe
iptables -A INPUT -s $ip_rede -p tcp --dport 5959 -j ACCEPT # NFe
## Caixa Economica
# -------------------------------------------------------
iptables -A INPUT -s $ip_rede -p tcp --dport 2006 -j ACCEPT # COBCaixa
iptables -A INPUT -s $ip_rede -p tcp --dport 2631 -j ACCEPT # CSocial
iptables -A INPUT -s $ip_rede -p tcp --dport 1024 -j ACCEPT
iptables -A INPUT -s $ip_rede -p tcp --dport 65535 -j ACCEPT
## Liberar ping (ICMP)
#--------------------------------------------------------
iptables -A INPUT -p icmp --icmp-type 0 -m limit --limit 2/s -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 3 -m limit --limit 2/s -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 5 -m limit --limit 2/s -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 8 -m limit --limit 2/s -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 11 -m limit --limit 2/s -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 12 -m limit --limit 2/s -j ACCEPT
## Fechando as portas do samba caso fique de cara para a internet.
# -------------------------------------------------------
#TCP
iptables -A INPUT -i $net -p tcp --dport 137 -j DROP
iptables -A INPUT -i $net -p tcp --dport 138 -j DROP
iptables -A INPUT -i $net -p tcp --dport 139 -j DROP
iptables -A INPUT -i $net -p tcp --dport 445 -j DROP
#UDP
iptables -A INPUT -i $net -p udp --dport 137 -j DROP
iptables -A INPUT -i $net -p udp --dport 138 -j DROP
iptables -A INPUT -i $net -p udp --dport 139 -j DROP
iptables -A INPUT -i $net -p udp --dport 445 -j DROP
## Bloqueando U89 - software burlador de proxy
# -------------------------------------------------------
iptables -A FORWARD -p tcp --dport 9666 -j DROP
iptables -A INPUT -p tcp --dport 9666 -j DROP
iptables -A OUTPUT -p tcp --dport 9666 -j DROP
# BLoqueio de UltraSurf
# -------------------------------------------------------
iptables -A INPUT -d 65.49.14.0/24 -j LOG --log-prefix "=UltraSurf= "
iptables -A FORWARD -d 65.49.14.0/24 -j LOG --log-prefix "=UltraSurf= "
## Bloqueio de Multicast
# -------------------------------------------------------
iptables -A INPUT -s 224.0.0.0/4 -j DROP
iptables -A INPUT -d 224.0.0.0/4 -j DROP
iptables -A INPUT -s 240.0.0.0/5 -j DROP
iptables -A INPUT -d 240.0.0.0/5 -j DROP
iptables -A INPUT -s 0.0.0.0/8 -j DROP
iptables -A INPUT -d 0.0.0.0/8 -j DROP
iptables -A INPUT -d 239.255.255.0/24 -j DROP
iptables -A INPUT -d 255.255.255.255 -j DROP
## Bloqueio de Black Orifice
# -------------------------------------------------------
iptables -A INPUT -p tcp --dport 12345:12345 -j DROP
iptables -A INPUT -p udp --dport 12345:12345 -j DROP
## Bloqueio acesso X server
# -------------------------------------------------------
iptables -A INPUT -p tcp --dport 5999:6003 -j DROP
iptables -A INPUT -p udp --dport 5999:6003 -j DROP
iptables -A INPUT -p tcp --dport 7100 -j DROP
## Bloqueio de NetBus
# -------------------------------------------------------
iptables -A INPUT -p tcp --dport 31337 -j DROP
iptables -A INPUT -p udp --dport 31337 -j DROP
## Protecao Contra IP Spoofing
# -------------------------------------------------------
iptables -A INPUT -i $net -s 10.0.0.0/8 -j DROP
iptables -A INPUT -i $net -s 127.0.0.0/8 -j DROP
iptables -A INPUT -i $net -s 169.254.0.0/16 -j DROP
iptables -A INPUT -i $net -s 172.16.0.0/12 -j DROP
iptables -A INPUT -i $net -s 192.168.0.0/24 -j DROP
# Impedindo ataque Ping of Death na rede
# -------------------------------------------------------
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
# Impedindo ataque de Denial Of Service Dos na rede e servidor
# -------------------------------------------------------
iptables -A FORWARD -p tcp -m limit --limit 1/s -j ACCEPT
iptables -A INPUT -p tcp -m limit --limit 1/s -j ACCEPT
# Protecao contra worms
# -------------------------------------------------------
iptables -I FORWARD -p tcp --dport 135 -j LOG --log-level info --log-prefix 'WORMS REDE>'
iptables -A FORWARD -p tcp --dport 135 -j DROP
iptables -I INPUT -p tcp --dport 135 -j LOG --log-level info --log-prefix 'WORMS >'
iptables -A INPUT -p tcp --dport 135 -j DROP
# Bloquear ataque do tipo SYN-FLOOD
# -------------------------------------------------------
iptables -A INPUT -i $net -p tcp ! --syn -m conntrack --ctstate NEW -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "Drop Syn"
iptables -A INPUT -i $net -p tcp ! --syn -m conntrack --ctstate NEW -j DROP
# Fragmentos
# -------------------------------------------------------
iptables -A INPUT -i $net -f -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "Fragments Packets"
iptables -A INPUT -i $net -f -j DROP
iptables -A INPUT -i $net -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
iptables -A INPUT -i $net -p tcp --tcp-flags ALL ALL -j DROP
# Bloquear pacotes NULL
# -------------------------------------------------------
iptables -A INPUT -i $net -p tcp --tcp-flags ALL NONE -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "NULL Packets"
iptables -A INPUT -i $net -p tcp --tcp-flags ALL NONE -j DROP # NULL packets
iptables -A INPUT -i $net -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
# Drop xmas
# -------------------------------------------------------
iptables -A INPUT -i $net -p tcp --tcp-flags SYN,FIN SYN,FIN -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "XMAS Packets"
iptables -A INPUT -i $net -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP #XMAS
# Drop FIN scans
# -------------------------------------------------------
iptables -A INPUT -i $net -p tcp --tcp-flags FIN,ACK FIN -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "Fin Packets Scan"
iptables -A INPUT -i $net -p tcp --tcp-flags FIN,ACK FIN -j DROP # FIN packet scans
iptables -A INPUT -i $net -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
# Log and get rid of broadcast / multicast and invalid
# -------------------------------------------------------
iptables -A INPUT -i $net -m pkttype --pkt-type broadcast -j LOG --log-prefix " Broadcast "
iptables -A INPUT -i $net -m pkttype --pkt-type broadcast -j DROP
iptables -A INPUT -i $net -m pkttype --pkt-type multicast -j LOG --log-prefix " Multicast "
iptables -A INPUT -i $net -m pkttype --pkt-type multicast -j DROP
iptables -A INPUT -i $net -m conntrack --ctstate INVALID -j LOG --log-prefix " Invalid "
iptables -A INPUT -i $net -m conntrack --ctstate INVALID -j DROP
# Liberar toda conexão de saída, sem entrada stuff
# -------------------------------------------------------
iptables -A INPUT -i $net -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -o $net -m conntrack --ctstate NEW,ESTABLISHED,RELATED -j ACCEPT
# Protecao contra nmap
# -------------------------------------------------------
iptables -A INPUT -p tcp -i $net -m conntrack --ctstate NEW -m recent --set
iptables -A INPUT -p tcp -i $net -m conntrack --ctstate NEW -m recent --update --seconds 30 --hitcount 10 -j LOG --log-prefix "TENTATIVA SCAN "
iptables -A INPUT -p tcp -i $net -m conntrack --ctstate NEW -m recent --update --seconds 30 --hitcount 10 -j DROP
# Mais protecao contra portscanner
# -------------------------------------------------------
iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i $net -j DROP
# Drop invalid packets
# -------------------------------------------------------
iptables -A INPUT -m conntrack --ctstate INVALID -j DROP
iptables -A FORWARD -m conntrack --ctstate INVALID -j DROP
iptables -A OUTPUT -m conntrack --ctstate INVALID -j DROP
# Stop smurf attacks
# -------------------------------------------------------
iptables -A INPUT -p icmp -m icmp --icmp-type address-mask-request -j DROP
iptables -A INPUT -p icmp -m icmp --icmp-type timestamp-request -j DROP
# Drop excessive RST packets to avoid smurf attacks
# -------------------------------------------------------
iptables -A INPUT -p tcp -m tcp --tcp-flags RST RST -m limit --limit 2/second --limit-burst 2 -j ACCEPT
# Don't allow pings through
# -------------------------------------------------------
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j DROP
# fecha de hosts conhecidos como spam / bots
# -------------------------------------------------------
FILE=/etc/squid3/lists/drop.lasso
blocks=$(cat $FILE | egrep -v '^;' | awk '{ print $1}' )
for ipblock in $blocks ;do
iptables -A INPUT -s $ipblock -j DROP
done
echo "Bloqueio Hosts indevidos...........................[OK]"
#Bloqueio de scanners ocultos (Shealt Scan)
# -------------------------------------------------------
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
iptables -A FORWARD --protocol tcp --tcp-flags ALL SYN,ACK -j DROP
iptables -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
iptables -A INPUT -s 0.0.0.0/0 -p icmp -j DROP
## Protecao diversas contra portscanners, ping of death, ataques DoS, etc.
# -------------------------------------------------------
iptables -A INPUT -i $net -f -j LOG --log-prefix "Pacote INPUT fragmentado: "
iptables -A INPUT -i $net -f -j DROP
# Bloqueio de tracertroute
# -------------------------------------------------------
iptables -A INPUT -p udp -s 0/0 -i $net --dport 33435:33525 -j DROP
## Protecao contra port VALID_CHECK
# -------------------------------------------------------
iptables -N VALID_CHECK
iptables -A VALID_CHECK -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags ALL ALL -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags ALL FIN -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags ALL NONE -j DROP
## Protecao contra port scanners
# -------------------------------------------------------
iptables -N SCANNER
iptables -A SCANNER -m limit --limit 5/m -j LOG --log-level 6 --log-prefix "FIREWALL: port scanner: "
iptables -A SCANNER -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j SCANNER
## Protecao contra tronjans
# -------------------------------------------------------
iptables -N TROJAN
iptables -A TROJAN -m limit --limit 5/m -j LOG --log-level 6 --log-prefix "FIREWALL: trojan: "
iptables -A TROJAN -j DROP
iptables -A INPUT -p tcp --dport 666 -j TROJAN
iptables -A INPUT -p tcp --dport 666 -j TROJAN
iptables -A INPUT -p tcp --dport 4000 -j TROJAN
iptables -A INPUT -p tcp --dport 6000 -j TROJAN
iptables -A INPUT -p tcp --dport 6006 -j TROJAN
iptables -A INPUT -p tcp --dport 16660 -j TROJAN
## Protecao contra trinoo
# -------------------------------------------------------
iptables -N TRINOO
iptables -A TRINOO -m limit --limit 5/m -j LOG --log-level 6 --log-prefix "FIREWALL: trinoo: "
iptables -A TRINOO -j DROP
iptables -A INPUT -p tcp --dport 1524 -j TRINOO
iptables -A INPUT -p tcp --dport 27444 -j TRINOO
iptables -A INPUT -p tcp --dport 27665 -j TRINOO
iptables -A INPUT -p tcp --dport 31335 -j TRINOO
iptables -A INPUT -p tcp --dport 34555 -j TRINOO
iptables -A INPUT -p tcp --dport 35555 -j TRINOO
# Fecha todas as portas
# -------------------------------------------------------
iptables -A INPUT -p tcp --dport 3128 -j REJECT --reject-with tcp-reset
## ReceitaNET
# -----------------------------------------------------
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 161.148.185.130 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 161.148.185.130 --dport 443 -j ACCEPT
iptables -t nat -A PREROUTING -s $ip_rede -d 161.148.185.130 -p tcp --dport 80 -j REDIRECT --to-ports 3128
## Dapi-sef
# -------------------------------------------------------
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 200.166.92.41 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 200.166.92.41 --dport 443 -j ACCEPT
iptables -t nat -A PREROUTING -s $ip_rede -d 200.166.92.41 -p tcp --dport 80 -j REDIRECT --to-ports 3128
# -------------------------------------------------------
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 201.16.234.41 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 201.16.234.41 --dport 443 -j ACCEPT
iptables -t nat -A PREROUTING -s $ip_rede -d 201.16.234.41 -p tcp --dport 80 -j REDIRECT --to-ports 3128
## Liberando acesso a NFE (Nota fiscal Eletronica)
# -------------------------------------------------------
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 200.189.133.249 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 200.189.133.249 --dport 443 -j ACCEPT
iptables -t nat -A PREROUTING -s $ip_rede -d 200.189.133.249 -p tcp --dport 80 -j REDIRECT --to-ports 3128
## Caixa Economica
# -------------------------------------------------------
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 200.201.174.207 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 200.201.174.207 --dport 443 -j ACCEPT
iptables -t nat -A PREROUTING -s $ip_rede -d 200.201.174.207 -p tcp --dport 80 -j REDIRECT --to-port 3128
## Bradesco
# -------------------------------------------------------
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 200.155.86.35 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 200.155.86.35 --dport 443 -j ACCEPT
iptables -t nat -A PREROUTING -s $ip_rede -d 200.155.86.35 -p tcp --dport 80 -j REDIRECT --to-port 3128
## Cedente
# -------------------------------------------------------
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 189.75.117.230 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 189.75.117.230 --dport 443 -j ACCEPT
iptables -t nat -A PREROUTING -s $ip_rede -d 189.75.117.230 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 186.215.92.131 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s $ip_rede -p tcp -d 186.215.92.131 --dport 443 -j ACCEPT
iptables -t nat -A PREROUTING -s $ip_rede -d 186.215.92.131 -p tcp --dport 80 -j REDIRECT --to-port 3128
;;
stop)
log_daemon_msg "Stopping Firewall execution" "IPTABLES"
log_end_msg $?
## Zera regras
# -------------------------------------------------------
# Removendo regras
iptables -F
iptables -t nat -F
iptables -t mangle -F
# Apagando chains
iptables -X
iptables -t nat -X
iptables -t mangle -X
# Zerando contadores
iptables -Z
iptables -t nat -Z
iptables -t mangle -Z
## Determina a politica ACCEPT
# -------------------------------------------------------
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
echo "1" > /proc/sys/net/ipv4/ip_forward
## ACCEPT (libera) pacotes de retorno da internet
# -------------------------------------------------------
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
## Abre para a interface de loopback.
# -------------------------------------------------------
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp --syn -s 127.0.0.1/24 -j ACCEPT
## Mascaramento de rede para acesso externo
# -------------------------------------------------------
iptables -t nat -A POSTROUTING -s $ip_rede -j MASQUERADE
# Libera HTTP e HTTPS
# -------------------------------------------------------
iptables -A INPUT -s $ip_rede -p tcp -j ACCEPT
iptables -A INPUT -s $ip_rede -p udp -j ACCEPT
;;
restart)
$0 stop
$0 start
;;
status)
;;
*)
echo "Use: ./firewall {start|stop|restart|status}"
exit 1
esac
exit 0