lucas_vga
(usa Ubuntu)
Enviado em 16/11/2010 - 16:53h
#!/bin/bash
EXTERNA="eth0"
INTERNA="eth1"
ipt=$(which iptables)
# Carregar modulos
# -------------------------------------------------------
echo "Carregando Modulos"
# Fazer NAT, de forma geral compatilhada a internet com forward
# -------------------------------------------------------
/sbin/modprobe iptable_nat
# Ativa os modulos de FTP
# -------------------------------------------------------
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
# Utilizado nas opcoes que geram log.
# -------------------------------------------------------
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_REJECT
/sbin/modprobe ipt_MASQUERADE
echo "Modulos Carregados [OK]"
# Zera as regras existentes
# -------------------------------------------------------
echo "Limpando regras existentes"
$ipt -F
$ipt -X
$ipt -F -t nat
$ipt -X -t nat
$ipt -F -t mangle
$ipt -X -t mangle
echo "Regras resetadas [OK]"
# Tratando regras
# -------------------------------------------------------
echo "Fechando as regras padroes"
$ipt -P INPUT ACCEPT
$ipt -P OUTPUT ACCEPT
$ipt -P FORWARD ACCEPT
echo "Regras padroes fechadas [OK]"
# ACCEPT (libera) pacotes de retorno da internet
# -------------------------------------------------------
$ipt -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$ipt -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
# Faz O NAT compartilhando a conexao
# -------------------------------------------------------
$ipt -A POSTROUTING -t nat -o $EXTERNA -j MASQUERADE
echo "1" > /proc/sys/net/ipv4/ip_forward
# Diminui o tamanho dos pacotes da rede
# -------------------------------------------------------
$ipt -A FORWARD -p tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1400:1536 -j TCPMSS --clamp-mss-to-pmtu
# Protecao contra IP spoofing
# -------------------------------------------------------
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
# Liberando a interface lo e o localhost
# -------------------------------------------------------
$ipt -t filter -A INPUT -i lo -j ACCEPT
$ipt -t filter -A INPUT -s 127.0.0.1 -j ACCEPT
# Aceita conexos externas do DNS
# -------------------------------------------------------
$ipt -A INPUT -i $INTERNA -p tcp --dport 53 -j ACCEPT
$ipt -A INPUT -i $INTERNA -p udp --dport 53 -j ACCEPT
# Libera acesso externo para servidor web
# -------------------------------------------------------
$ipt -A FORWARD -p tcp -m multiport --dports http,https -i $INTERNA -j ACCEPT
# Libera acesso ssh
# -------------------------------------------------------
$ipt -A INPUT -p tcp --dport 22 -i $EXTERNA -j ACCEPT
$ipt -A INPUT -p tcp --dport 22 -i $INTERNA -j ACCEPT
# Liberando servico de ftp
# -------------------------------------------------------
$ipt -A FORWARD -p tcp --dport 20 -j ACCEPT
$ipt -A FORWARD -p tcp --dport 21 -j ACCEPT
# Liberar acesso ao msn
# -------------------------------------------------------
#$ipt -A FORWARD -p tcp --dport 1863 -j ACCEPT
#$ipt -A FORWARD -p udp --dport 1863 -j ACCEPT
#$ipt -A FORWARD -p tcp --sport 1863 -j ACCEPT
#$ipt -A FORWARD -p udp --sport 1863 -j ACCEPT
#$ipt -A INPUT -p tcp --dport 1863 -j ACCEPT
#$ipt -A INPUT -p tcp --dport 1863 -j ACCEPT
#$ipt -A INPUT -p tcp --sport 1863 -j ACCEPT
#$ipt -A INPUT -p tcp --sport 1863 -j ACCEPT
#iptables -A FORWARD -d loginnet.passport.com -j ACCEPT
#iptables -A FORWARD -d 64.4.13.0/24 -j ACCEPT
#iptables -A FORWARD -d login.live.com -j ACCEPT
#iptables -A FORWARD -d login.passport.com -j ACCEPT
#iptables -A FORWARD -d gateway.messenger.hotmail.com -j ACCEPT
#iptables -A FORWARD -d messenger.msn.com -j ACCEPT
#iptables -A FORWARD -d login.passport.net -j ACCEPT
#iptables -A INPUT -p tcp --dport 1863 -j ACCEPT
#iptables -A INPUT -d loginnet.passport.com -j ACCEPT
#iptables -A INPUT -d 64.4.13.0/24 -j ACCEPT
#iptables -A INPUT -d login.live.com -j ACCEPT
#iptables -A INPUT -d login.passport.com -j ACCEPT
#iptables -A INPUT -d gateway.messenger.hotmail.com -j ACCEPT
#iptables -A INPUT -d messenger.msn.com -j ACCEPT
#iptables -A INPUT -d login.passport.net -j ACCEPT
# Libera POP e SMTP
# -------------------------------------------------------
$ipt -A FORWARD -p tcp -m multiport --dports smtp,pop3,submission -j ACCEPT
# Libera um pc pelo mac para acessar sem firewall
# -------------------------------------------------------
#iptables -t nat -A PREROUTING -p tcp -m mac --mac-source XX:XX:XX:XX:XX:XX -j ACCEPT
# Libera porta 3128 do squid
#--------------------------------------------------------
$ipt -A INPUT -p tcp --dport 3128 -i $INTERNA -j ACCEPT
# Libera porta 80 do squid
#--------------------------------------------------------
$ipt -A INPUT -p tcp --dport 80 -i $INTERNA -j ACCEPT
$ipt -A INPUT -p tcp --dport 80 -i $EXTERNA -j ACCEPT
# Tentativa de redirecionamento portas para o ip interno, sistema de VOIP
# -------------------------------------------------------
iptables -A FORWARD -i $EXTERNA -m multiport -p tcp --dport 4000:9000 -j ACCEPT
iptables -A INPUT -i $EXTERNA -m multiport -p tcp --dport 4000:9000 -j ACCEPT
iptables -A FORWARD -s 192.168.0.111 -j ACCEPT
iptables -t nat -A PREROUTING -d 187.76.219.252 -m multiport -p tcp --dport 4000:9000 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -m multiport -p tcp --dport 10000:20000 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -p tcp --dport 5060 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -p tcp --dport 443 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -p tcp --dport 4569 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -m multiport -p tcp --dport 40000:65535 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -p tcp --dport 5061 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -p udp --dport 5061 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -m multiport -p udp --dport 40000:65535 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -p udp --dport 4569 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -m multiport -p udp --dport 4000:9000 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -m multiport -p udp --dport 10000:20000 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -p udp --dport 5060 -j DNAT --to 192.168.0.111
iptables -t nat -A PREROUTING -d 187.76.219.252 -p udp --dport 443 -j DNAT --to 192.168.0.111
#--------------------------------------------------------
# Redireciona trafego da porta 80 para a 3128
# -------------------------------------------------------
$ipt -t nat -A PREROUTING -i $INTERNA -p tcp --dport 80 -j REDIRECT --to-port 3128