hugovlmota
(usa CentOS)
Enviado em 29/08/2007 - 15:45h
#eth1=placa externa
#eth0=placa interna
#limpas as regras
iptables -F
iptables -X
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
#carrega modulos
modprobe iptable_nat
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ipt_LOG
modprobe ipt_REJECT
modprobe ipt_MASQUERADE
modprobe ipt_multiport
# HABILITA FORWARD
echo "1" >/proc/sys/net/ipv4/ip_forward
#proxy transparente
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
#Proteção contra ataques
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 1 > /proc/sys/net/ipv4/icmp_ignore_all
#fitros de IP
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/eth1/rp_filter
#proteção contra ataques
iptables -A INPUT -p tcp -i eth1 --dport 1524 -j DROP
iptables -A INPUT -p tcp -i eth1 --dport 27665 -j DROP
iptables -A INPUT -p udp -i eth1 --dport 27444 -j DROP
iptables -A INPUT -p udp -i eth1 --dport 31335 -j DROP
iptables -A FORWARD -m unclean -j DROP
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 2/s -j ACCEPT
iptables -A FORWARD -p tcp -m limit --limit 5/s -j ACCEPT
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j LOG --log-prefix "FTP"
iptables -A INPUT -p tcp --dport 23 -j LOG --log-prefix "TELNET"
iptables -A INPUT -p tcp --dport 22 -j LOG --log-prefix "SSH "
iptables -A INPUT -p tcp --dport 137:139 -j LOG --log-prefix "NETBEUI"
iptables -A INPUT -p tcp --dport 5042 -j LOG --log-prefix "Wincrash"
iptables -A INPUT -p tcp --dport 12345 -j LOG --log-prefix "BackOrifice"
#Libera loopback
iptables -A OUTPUT -p .tcp --syn -s 127.0.0.1/255.0.0.0 -j ACCEPT
# Liberando acesso para sua rede interna
iptables -A INPUT -p tcp --syn -s 192.168.1.0/255.255.255.0 -j ACCEPT &&
iptables -A OUTPUT -p tcp --syn -s 192.168.1.0/255.255.255.0 -j ACCEPT &&
iptables -A FORWARD -p tcp --syn -s 192.168.1.0/255.255.255.0 -j ACCEPT &&
#conexoes de fora->dentro
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 563 -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -p tcp --dport 110 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 86 -j ACCEPT
iptables -A INPUT -p tcp --dport 5190 -j ACCEPT
iptables -A INPUT -p tcp --dport 1863 -j ACCEPT
iptables -A INPUT -p tcp --dport 5800 -j ACCEPT
iptables -A INPUT -p tcp --dport 5900 -j ACCEPT
#conexoes dentro->fora
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 20 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 21 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 86 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 5190 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 1863 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 25 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 110 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 563 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 5800 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 5900 -j ACCEPT
#correio eletronco
iptables -A FORWARD -p tcp -s 192.168.1.0/24 -d 201.7.95.96 --dport 53 -j ACCEPT
iptables -A FORWARD -p tcp -s 201.7.95.96 --sport 53 -d 192.168.1.0/24 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.1.0/24 --dport 25 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.1.0/24 --dport 110 -j ACCEPT
iptables -A FORWARD -p tcp --sport 25 -j ACCEPT
iptables -A FORWARD -p tcp --sport 110 -j ACCEPT
#conectividade social
iptables -A FORWARD -p tcp --dport 2631 -j ACCEPT
iptables -A FORWARD -p udp --dport 2631 -j ACCEPT
#CAT porta 5017 / Sintegra porta 8017 (cafe.dataprev.gov.br=200.152.32.148)
iptables -A FORWARD -s 192.168.1.0/24 -p tcp --dport 5017 -j ACCEPT
iptables -A FORWARD -s 192.168.1.0/24 -p tcp --dport 8017 -j ACCEPT
#libera HTTPS
iptables -A FORWARD -p tcp --dport 443 -j ACCEPT
iptables -A FORWARD -p tcp --dport 563 -j ACCEPT
#VNC
iptables -A FORWARD -i eth1 -p tcp --dport 5800:5900 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth1 -p udp --dport 5800:5900 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 5800:5900 -j DNAT --to 192.168.1.1:5800-5900
iptables -t nat -A PREROUTING -p udp -i eth1 --dport 5800:5900 -j DNAT --to 192.168.1.1:5800-5900
#fecha o resto
iptables -A INPUT -j DROP
iptables -A FORWARD -j DROP