maumauns
(usa RedHat)
Enviado em 25/09/2014 - 15:09h
Boa tarde pessoal, estou com um script de firewall
e estou com interesse de aplica-lo em minha rede aqui.
Gostei dele pois ele trabalha com as politicas em drop por padrão,
mais estou tendo problemas aqui, não estou conseguindo compartilhar a internet com as maquinas locais.
Segue o script, como falei eu não tenho erro, apenas a internet não esta sendo compartilhada com as maquinas locais.
#!/bin/bash
##### Ativando modulos
/sbin/modprobe iptable_nat
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_REJECT
/sbin/modprobe ipt_MASQUERADE
##### Limpando Regras Anteriormente Aplicadas e Apagando Chains Anteriormente Criadas
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
##### Definindo Politica de Policiamento Padrao
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
##### Ativa Roteamento no Kernel
echo "1" > /proc/sys/net/ipv4/ip_forward
##### Protecao Contra IP Spoofing
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
##### Ativando Compartinhamento de Conexao
iptables -A POSTROUTING -t nat -s 192.168.0.0/24 -o eth1 -j MASQUERADE
##### Squid - Proxy
#iptables -t nat -A PREROUTING -p tcp -m multiport -s 192.168.0.0/24 --dport 80 -j REDIRECT --to-ports 3128
##### DROP nos pacotes TCP indesejaveis
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j LOG --log-level 6 --log-prefix "FIREWALL: NEW sem syn: "
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
##### ACCEPT - Liberar Pacotes de Retorno da Internet
iptables -A INPUT -i ! eth1 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
##### DROP e LOG de Port Scanners
iptables -N SCANNER
iptables -A SCANNER -m limit --limit 15/m -j LOG --log-level 6 --log-prefix "DIVERSOS: port scanner: "
iptables -A SCANNER -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL NONE -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL ALL -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i eth1 -j SCANNER
##### LOG de Acesso por Porta
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 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 3128 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: squid: "
##### Regras BitTorrent
iptables -A INPUT -p tcp -i eth1 --syn --dport 139 -j DROP
iptables -A INPUT -p tcp -i eth1 --syn --dport 138 -j DROP
iptables -A INPUT -p tcp -i eth1 --syn --dport 137 -j DROP
##### Fechar NFS (PortMap)
iptables -A INPUT -p tcp -i eth1 --syn --dport 111 -j DROP
##### Libera Acesso Externo e Interno para SSH e APACHE
iptables -A INPUT -p tcp --dport 80 -i eth0 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -i eth1 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -i eth0 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -i eth1 -j ACCEPT
##### Regras Iptables para Bloquear Ataques Brute Force no SSH
iptables -A INPUT -p tcp --syn --dport 22 -m recent --name sshattack --set
iptables -A INPUT -p tcp --dport 22 --syn -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j LOG --log-prefix 'SSH REJECT: '
iptables -A INPUT -p tcp --dport 22 --syn -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j REJECT --reject-with tcp-reset
iptables -A FORWARD -p tcp --syn --dport 22 -m recent --name sshattack --set
iptables -A FORWARD -p tcp --dport 22 --syn -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j LOG --log-prefix 'SSH REJECT: '
iptables -A FORWARD -p tcp --dport 22 --syn -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j REJECT --reject-with tcp-reset
##### Liberar Conectividade Social
iptables -t nat -I PREROUTING -p tcp -d 200.201.0.0/16 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 200.223.0.0 -j ACCEPT
iptables -I FORWARD -p tcp -d 200.201.0.0/16 -j ACCEPT
iptables -I FORWARD -p tcp -d 200.223.0.0 -j ACCEPT
##### Liberar CAT Dataprev
iptables -I FORWARD -s 192.168.0.0/24 -p tcp -d 200.152.32.148 --dport 5017 -j ACCEPT
iptables -I FORWARD -s 200.152.32.148 -p tcp -d 192.168.0.0/24 --dport 5017 -j ACCEPT
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d ! 200.152.32.148 -p tcp --dport 5017 -j REDIRECT --to-port 3128
##### Redirecionando Requisicoes para o Terminal Service - Windows 2003 Server
iptables -I FORWARD -s 0/0 -p tcp -d 192.168.0.5 --dport 3389 -j ACCEPT
iptables -I FORWARD -s 192.168.0.5 -p tcp -d 0/0 --dport 3389 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3389 -j DNAT --to 192.168.0.5