alxbf
(usa CentOS)
Enviado em 17/10/2012 - 16:24h
# habilitando o roteamento
echo 1 > /proc/sys/net/ipv4/ip_forward
# limpando as regras anteriores
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
# habilitando os modulos
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ip_queue
modprobe ipt_LOG
modprobe ipt_MARK
modprobe ip_tables
modprobe ipt_MASQUERADE
modprobe ipt_REDIRECT
modprobe ipt_REJECT
modprobe ipt_tos
modprobe ipt_limit
modprobe ipt_state
modprobe ipt_mac
modprobe ipt_multiport
modprobe iptable_filter
modprobe iptable_mangle
modprobe iptable_nat
# regras
# liberando porta 443 dns
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# liberando loopback
iptables -A OUTPUT -p tcp --syn -s 127.0.0.1/255.0.0.0 -j ACCEPT
# liberando acessos internos para firewall
iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT
# logs de porta proibidas
#iptables -A INPUT -p tcp --dport 21 -j --log-prefix "Servico FTP"
#iptables -A INPUT -p tcp --dport 110 -j --log-prefix "Servico POP"
#iptables -A INPUT -p tcp --dport 587 -j --log-prefix "Servico SMTP-587"
#iptables -A INPUT -p tcp --dport 25 -j --log-prefix "Servico SMTP-25"
# habilitando porta SSH
iptables -A INPUT -p tcp -s 192.168.0.0/24 --dport 22 -j ACCEPT
# habilitando porta SMTP
#iptables -A INPUT -p tcp -s 192.168.0.0/24 --dport 25 -j ACCEPT
#iptables -A INPUT -p tcp -s 192.168.0.0/24 --dport 587 -j ACCEPT
iptables -A INPUT -p tcp --dport 587 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
# habilitando porta dns
iptables -A INPUT -p tcp -s 192.168.0.0/24 --dport 53 -j ACCEPT
iptables -A INPUT -p udp -s 192.168.0.0/24 --sport 53 -j ACCEPT
# habilitando porta pop3
#iptables -A INPUT -p tcp -s 192.168.0.0/24 --dport 110 -j ACCEPT
iptables -A INPUT -p tcp --dport 110 -j ACCEPT
# redireciona portas
iptables -t nat -A PREROUTING -s x.x.x.x -i eth1 -j DNAT --to 192.168.0.7/24
iptables -t nat -A POSTROUTING -s x.x.x.x -o eth1 -p tcp --dport 3389 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.100.7/24 -o eth1 -j SNAT --to x.x.x.x
iptables -t nat -A POSTROUTING -s 192.168.100.7/24 -0 eth1 -p tcp --dport 3389 -j ACCEPT
# redirecionando porta 3128
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
# liberando todos os pacotes porta 25
iptables -A FORWARD -p tcp --dport 25 -j ACCEPT
iptables -A FORWARD -p tcp --dport 587 -j ACCEPT
#
iptables -A FORWARD -p tcp --dport 110 -j ACCEPT
#
iptables -A FORWARD -p udp --dport 53 -j ACCEPT
# liberando acesso interno da rede
iptables -A INPUT -p tcp --syn -s 192.168.0.0/24 -j ACCEPT
iptables -A OUTPUT -p tcp --syn -s 192.168.0.0/24 -j ACCEPT
iptables -A FORWARD -p tcp --syn -s 192.168.0.0/24 -j ACCEPT
# compartilhando a internet com a rede interna
#iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE
#iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -m multport -p tcp --dport 25,110,143,587 -j SNAT --to x.x.x.x
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A FORWARD -o eth1 -s 192.168.0.0/24 -d 0/0 -j ACCEPT
# bloqueando traceroute
iptables -A INPUT -p udp -s 0/0 -i eth1 --dport 33435:33525 -j DROP
# bloqueando contra ataques
iptables -A INPUT -m state --state INVALID -j DROP
# protecao contra ip spoofing
iptables -A INPUT -s 172.16.0.0/16 -i eth1 -j DROP
iptables -A INPUT -s 192.168.0.0/24 -i eth1 -j DROP
# protecao contra syn-floods
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
# protecao contra port scanners
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
# protecao contra DDOS
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
# bloqueando pacotes fragmentados
iptables -A INPUT -i eth1 -m unclean -j log_unclean
iptables -A INPUT -f -i eth1 -j log_fragment