leoventura
(usa Debian)
Enviado em 31/07/2008 - 17:46h
Blz...entao vamo faze o seguinte...
Eu posto o script e vcs me ajudam a melhora-lo.
Mas aee....se perceberem alguma bobeira nele sejam sinceros e me mostrem...mas sem esculachar...rsrsr...ainda to aprendendo.
Vamo lah....
#!/bin/bash
IPTABLES=/sbin/iptables
SSH_PORT=22
SQUID_PORT=3128
MSN=1863
IF_IN=eth1
IF_EX=ppp0
REDE=192.168.0.0/24
#excluindo regras
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
#excluindo cadeias criadas
$IPTABLES -X
#zerando contadores das cadeias
$IPTABLES -Z
$IPTABLES -t nat -Z
$IPTABLES -t mangle -Z
#setando politicas
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD DROP
$IPTABLES -P OUTPUT DROP
#--------INPUT--------
$IPTABLES -A INPUT -i lo -s 127.0.0.1/8 -d 127.0.0.1/8 -j ACCEPT
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -i $IF_IN -s $REDE -p tcp --dport $SQUID_PORT -j ACCEPT
#--------OUTPUT-------
$IPTABLES -A OUTPUT -o lo -s 127.0.0.1/8 -d 127.0.0.1/8 -j ACCEPT
$IPTABLES -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
#------FORWARD--------
$IPTABLES -A FORWARD -p icmp --icmp-type echo-request -j ACCEPT
$IPTABLES -A FORWARD -p icmp --icmp-type echo-reply -j ACCEPT
$IPTABLES -A FORWARD -i eth1 -o ppp0 -s $REDE -p udp --dport 53 -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -o eth1 -d $REDE -p udp --sport 53 -j ACCEPT
$IPTABLES -A FORWARD -i eth1 -o ppp0 -s $REDE -p tcp --dport $SQUID_PORT -j ACCEPT
$IPTABLES -A FORWARD -i eth1 -o ppp0 -s $REDE -p tcp --dport 443 -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -o eth1 -d $REDE -p tcp --sport 443 -j ACCEPT
$IPTABLES -A FORWARD -i eth1 -o ppp0 -s $REDE -p tcp --dport 21 -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -o eth1 -d $REDE -p tcp --sport 21 -j ACCEPT
$IPTABLES -A FORWARD -i eth1 -o ppp0 -s $REDE -p tcp --dport $MSN -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -o eth1 -d $REDE -p tcp --sport $MSN -j ACCEPT
$IPTABLES -A FORWARD -i eth1 -o ppp0 -s $REDE -p tcp --dport $SSH -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -o eth1 -d $REDE -p tcp --sport $SSH -j ACCEPT
#--------NAT----------
$IPTABLES -t nat -A POSTROUTING -s $REDE -o $IF_EX -j MASQUERADE
#-------Redirecionamentos de conexoes-------
$IPTABLES -t nat -A PREROUTING -i $IF_IN -p tcp --dport 80 -j REDIRECT --to-port $SQUID_PORT
#------ Configuracoes do KERNEL ------#
#desabilitando respostas a ping
echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all
#protecao contra responses bogus
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
#protecao contra syn-flood
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
#protecao contra traceroute
echo 1 > /proc/sys/net/ipv4/conf/all/accept_source_route
#protecao contra ip spoofing
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
#habilitando forward
echo 1 > /proc/sys/net/ipv4/ip_forward
echo "Carregando as regras do Firewall..."