SebaCueto
(usa Debian)
Enviado em 04/11/2010 - 10:40h
No meu caso está assim:
#!/bin/bash
### VARIÁVEIS ###
IPT="/sbin/iptables"
MODPROBE="/sbin/modprobe"
IF_LO="lo"
IP_LO="127.0.0.1"
IF_EXT="eth2"
IP_EXT="172.21.2.5"
IF_INT="eth0"
IP_INT="192.168.10.1"
REDE_INT="192.168.10.0/24"
IP_ADM="0.0.0.0/0"
ANY="200.203.54.19/32"
### Carregando os Módulos ###
$MODPROBE ip_tables
$MODPROBE iptable_filter
$MODPROBE iptable_nat
$MODPROBE iptable_mangle
$MODPROBE ip_nat_ftp
$MODPROBE ip_conntrack
$MODPROBE ip_conntrack_ftp
### Apagando, Limpando as regras e zerando os contadores de bytes das chains ###
$IPT -F INPUT
$IPT -F FORWARD
$IPT -F OUTPUT
$IPT -F -t filter
$IPT -F -t nat
$IPT -F -t mangle
$IPT -X -t filter
$IPT -X -t nat
$IPT -X -t mangle
$IPT -Z -t filter
$IPT -Z -t nat
$IPT -Z -t mangle
### Policiamento padrão das chains ###
$IPT -P INPUT DROP
$IPT -P FORWARD DROP
$IPT -P OUTPUT ACCEPT
### Habilita Forward e Protecões do kernel ###
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
echo "0" > /proc/sys/net/ipv4/conf/all/log_martians #--> Loga Spoofinf
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter #--> Faz o Controle de Spoofing
echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route
echo "0" > /proc/sys/net/ipv4/conf/all/accept_redirects
echo "0" > /proc/sys/net/ipv4/tcp_ecn
echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo "1" > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo "35" > /proc/sys/net/ipv4/ip_default_ttl
#echo "0" > /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_log_out_of_window
### Nega Portas TCP ###
$IPT -N nega_tcp
$IPT -A nega_tcp -p tcp -s $ANY -i $IF_EXT -j REJECT --reject-with tcp-reset
### Tráfego ilimitado na interface de Loopback ###
$IPT -A INPUT -i $IF_LO -j ACCEPT
$IPT -A OUTPUT -o $IF_LO -j ACCEPT
### Proteção contra Crackers ###
### Proteção contra ping flood ###
$IPT -N ping-chain
$IPT -t filter -A ping-chain -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
$IPT -t filter -A ping-chain -j DROP
### Limita em 1 vez por segundo a passagem de pings ###
$IPT -t filter -A ping-chain -i $IF_EXT -p icmp --icmp-type echo-reply -m limit --limit 1/s -j RETURN
$IPT -t filter -A ping-chain -j DROP
### Proteção para os ataques syn floods ###
$IPT -N syn-chain
$IPT -t filter -A syn-chain -p tcp --syn -m limit --limit 2/s -j ACCEPT
$IPT -t filter -A syn-chain -j DROP
### CHAIN INPUT ###
#$IPT -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
$IPT -A INPUT -p icmp --icmp-type 8 -m limit --limit 1/s --limit-burst 1 -j ACCEPT
$IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPT -A INPUT -m state --state INVALID -j DROP
$IPT -A INPUT -m limit --limit 2/h --limit-burst 1 -j LOG --log-prefix "FW INPUT pacote morto:"
### CHAIN OUTPUT ###
$IPT -A OUTPUT -p tcp ! --syn -m state --state NEW -j DROP
$IPT -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPT -A OUTPUT -m state --state INVALID -j DROP
$IPT -A OUTPUT -m limit --limit 2/h --limit-burst 1 -j LOG --log-prefix "FW OUTPUT pacote morto:"
### CHAIN FORWARD ###
$IPT -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP #--> Barra pacotes sem flag "syn"
$IPT -A FORWARD -p icmp -s $REDE_INT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPT -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPT -A FORWARD -m state --state INVALID -j DROP
$IPT -A FORWARD -m limit --limit 2/h --limit-burst 1 -j LOG --log-prefix "FW FORWARD pacote morto:"
### CHAIN POSTROUTING ###
$IPT -t nat -A POSTROUTING -o $IF_EXT -j SNAT --to-source $IP_EXT
### Serviços ###
## FTP ##
$IPT -A FORWARD -s $REDE_INT -p tcp -i $IF_INT -o $IF_EXT --dport 20 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPT -A FORWARD -s $REDE_INT -p tcp -i $IF_INT -o $IF_EXT --dport 21 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
## SSH ##
$IPT -A INPUT -p tcp -s $IP_ADM -i $IF_EXT --dport "oculto" -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPT -A INPUT -p tcp -s $REDE_INT -i $IF_INT --dport "oculto" -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPT -A FORWARD -s $REDE_INT -p tcp -i $IF_INT -o $IF_EXT --dport "oculto" -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
## SMTP ##
$IPT -A FORWARD -p tcp -i $IF_INT -o $IF_EXT -d smtp."oculto".com.br --dport "oculto" -m state --state NEW -j ACCEPT
## POP3 ##
$IPT -A FORWARD -p tcp -i $IF_INT -o $IF_EXT -d pop."oculto".com.br --dport "oculto" -m state --state NEW -j ACCEPT
## DNS ##
$IPT -A INPUT -p udp -s $REDE_INT -i $IF_INT --dport 53 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPT -A FORWARD -s $REDE_INT -p udp -i $IF_INT -o $IF_EXT --dport 53 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPT -A FORWARD -s $REDE_INT -p tcp -i $IF_INT -o $IF_EXT --dport 53 -j ACCEPT
## Https ##
$IPT -A FORWARD -s $REDE_INT -p tcp -i $IF_INT -o $IF_EXT --dport 443 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
## Http ##
$IPT -A FORWARD -s $REDE_INT -p tcp -i $IF_INT -o $IF_EXT --dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
## SQUID ##
$IPT -A INPUT -p tcp -s $REDE_INT -i $IF_INT --dport 3128 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPT -t nat -A PREROUTING -s $REDE_INT -i $IF_INT -p tcp ! -d 200.201.0.0/16 --dport 80 -j REDIRECT --to-port 3128
## Samba ##
$IPT -A INPUT -p udp -s $REDE_INT -i $IF_INT --dport 137 -j ACCEPT
$IPT -A INPUT -p udp -s $REDE_INT -i $IF_INT --dport 138 -j ACCEPT
$IPT -A INPUT -p tcp -s $REDE_INT -i $IF_INT --dport 139 -j ACCEPT
$IPT -A INPUT -p tcp -s $REDE_INT -i $IF_INT --dport 445 -j ACCEPT
## DHCP ##
$IPT -A INPUT -p udp -s $REDE_INT -i $IF_INT --dport 67 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
## IRPF ##
$IPT -A FORWARD -s 0/0 -d 161.148.0.0/16 -j ACCEPT
$IPT -A FORWARD -p tcp -s 0/0 -d 161.148.0.0/16 --dport 3456 -j ACCEPT
$IPT -t nat -A POSTROUTING -s 0/0 -d 161.148.0.0/16 -j MASQUERADE
## PostgreSQL ##
$IPT -A INPUT -s $REDE_INT -p tcp --dport "oculto" -j ACCEPT
## UNREAL ##
$IPT -t nat -I PREROUTING -i eth2 -p udp --dport 7777:7779 -j DNAT --to-dest 192.168.10.161
$IPT -I FORWARD -p udp -i eth2 --dport 7777:7779 -d 192.168.10.161 -j ACCEPT
Poderia dar uma olhada e me dizer o que estou fazendo errado??
Obrigado