andre_ramos
(usa openSUSE)
Enviado em 30/11/2009 - 08:33h
Kara nao estou conseguindo identificar algum bloqueio relacionado a isso que vc me passou estou colocando o meu script do firewall ok
grato
#!/bin/bash
# Autor: Andre Chagas Ramos
# Data Criacao: 25/09/2009
# Data Modificacao: 30/11/2009
IPTABLES=/usr/sbin/iptables
NETWORK=eth1
WEB=eth0
iniciar () {
# Limpando as regras
$IPTABLES -F
$IPTABLES -Z
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
# Compatilhamento da conexao
echo 1 > /proc/sys/net/ipv4/ip_forward
echo "Ativando compatilhamento!"
# Politicas de acesso geral
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD DROP
# Manter conexoes ja estabelecidas para nao parar
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -m state --state INVALID -j DROP
# Bloqueia pacotes intencionamente mal-formados
$IPTABLES -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
$IPTABLES -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
$IPTABLES -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
$IPTABLES -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
# Evitando SYN_Flood
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
# Carregamento de Modulos
modprobe ip_nat_ftp
modprobe iptable_nat
modprobe ip_tables
modprobe ip_conntrack
modprobe ipt_MASQUERADE
modprobe ip_conntrack_ftp
# Aceita todo o trafego vindo do loopback e indo pro loopback
$IPTABLES -t filter -A INPUT -i lo -j ACCEPT
# Protecoes contra ataques #
$IPTABLES -A INPUT -m state --state INVALID -j DROP
$IPTABLES -A INPUT -i $NETWORK -s ! 192.168.0.0/24 -j DROP
# Redirecionando o trafego para a porta 3128
$IPTABLES -t nat -A PREROUTING -i $NETWORK -p tcp -d ! 200.201.174.207 --dport 80 -j REDIRECT --to-port 3128
#$IPTABLES -t nat -A PREROUTING -i $NETWORK -p tcp -d ! 200.201.174.207 --dport 443 -j REDIRECT --to-port 3128
$IPTABLES -A INPUT -i eth1 -j ACCEPT
# Bloquear o MSN
$IPTABLES -I FORWARD -s 192.168.1.0/24 -p tcp --dport 1863 -j REJECT
$IPTABLES -I FORWARD -s 192.168.1.0/24 -d loginnet.passport.com -j REJECT
# Liberar MSN para determinados IPS
#$IPTABLES -I FORWARD -s 192.168.1.0/24 -p tcp --dport 1863 -j ACCEPT #Andre
#$IPTABLES -I FORWARD -s 192.168.1.0/24 -d loginnet.passport.com -j ACCEPT #Andre
# Regras para liberar o outlook
$IPTABLES -A FORWARD -p udp -s 192.168.0.0/24 -d 200.175.182.139 --dport 53 -j ACCEPT
$IPTABLES -A FORWARD -p udp -s 200.175.182.139 --sport 53 -d 192.168.0.0/24 -j ACCEPT
$IPTABLES -A FORWARD -p udp -s 192.168.0.0/24 -d 200.175.5.139 --dport 53 -j ACCEPT
$IPTABLES -A FORWARD -p udp -s 200.175.5.139 --sport 53 -d 192.168.0.0/24 -j ACCEPT
$IPTABLES -A FORWARD -p tcp -s 192.168.0.0/24 --dport 25 -j ACCEPT # SMTP
$IPTABLES -A FORWARD -p tcp -s 192.168.0.0/24 --dport 587 -j ACCEPT # SMTP
$IPTABLES -A FORWARD -p tcp -s 192.168.0.0/24 --dport 110 -j ACCEPT # POP3
# Regras para liberar o FTP
$IPTABLES -A INPUT -i $NETWORK -p tcp -s 192.168.0.0/24 --dport 20 -j ACCEPT # FTP
$IPTABLES -A INPUT -i $NETWORK -p tcp -s 192.168.0.0/24 --dport 21 -j ACCEPT # FTP
# INPUT # Pacotes que entram na rede
$IPTABLES -A INPUT -i $NETWORK -p tcp --dport 22 -j ACCEPT # SSH
$IPTABLES -A INPUT -i $NETWORK -p tcp --dport 80 -j ACCEPT # HTTP
$IPTABLES -A INPUT -i $NETWORK -p tcp --dport 443 -j ACCEPT # HTTPS
# FORWARD # Pacotes que circulam na rede
$IPTABLES -A FORWARD -i $NETWORK -p tcp --dport 22 -j ACCEPT # SSH
$IPTABLES -A FORWARD -i $NETWORK -p tcp --dport 8333 -j ACCEPT # HTTP
$IPTABLES -A FORWARD -i $NETWORK -p tcp --dport 443 -j ACCEPT # HTTPS
$IPTABLES -A FORWARD -i $NETWORK -s 192.168.0.0/24 -j ACCEPT
# Mascaramento da rede para acesso externo
$IPTABLES -t nat -A POSTROUTING -o eth0 -j MASQUERADE
#--------------------------------------------------------------------------------------
echo "Firewall Ativado"
}
parar(){
echo "Regras de firewall e compartilhamento desativados"
iptables -F
iptables -t nat -F
iptables -t mangle -F
}
case "$1" in
"start") iniciar ;;
"stop") parar ;;
"restart") parar; iniciar;;
*)echo "Use os paramentros start ou stop"
esac