[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Pregunta IPTABLES



El 17/07/07, "Miguel J. Jiménez" <MiguelJose.Jimenez@isotrol.com> escribió:
Hola, tengo el siguiente script para configurar las IPTABLES, y me
gustaria saber vuestra opinión para saber si debo añadir algo más que no
esté... Soy bastante novato en IPTABLES :-(

--- BEGIN SCRIPT
#!/bin/bash
#
# Última modificación: 09/07/2007
#

printf "\n#################################\n";
printf "# Configuración de las IPTABLES #\n";
printf "#################################\n\n";

# DEFINICIÓN DE VARIABLES
IPT="sudo /sbin/iptables";    # Ruta al ejecutable del IPTABLES
IFCONFIG="/sbin/ifconfig";    # Ruta al ejecutable del IFCONFIG
EXT_IF="eth0";            # Interfaz de red a proteger
LAN="192.168.0.0/16";        # Parte de la red correspondiente a la LAN
IP=`$IFCONFIG $EXT_IF | grep "inet addr" | cut -d ":" -f 2 | cut -d " "
-f 1`; # Detectamos la IP asignada

PUERTOS_ABIERTOS=( # Especifica los puertos ENTRANTES que se abrirán
    "SSH:22"
    "HTTP:80"
    "HTTPS:443"
    "WEBCACHE:8080"
    "STICKIES:52673"
);

printf "* Detectada IP: $IP\n";

# POR DEFECTO DESECHAMOS TODOS LOS PAQUETES
printf "* Desechando TODOS los paquetes ... ";
$IPT -P INPUT DROP > /dev/null 2>&1 && $IPT -P OUTPUT DROP > /dev/null
2>&1 && $IPT -P FORWARD DROP > /dev/null 2>&1 && printf "OK\n" || printf
"FALLÓ\n";

# LIMPIAMOS LAS REGLAS ANTERIORES
printf "* Limpiando reglas anteriormente definidas ... ";
$IPT -F > /dev/null 2>&1 && printf "OK\n" || printf "FALLÓ\n";



priemro limpias y luego das las opciones por default




# PERMITIMOS TRÁFICO LOOPBACK
printf "* Permitiendo tráfico de loopback ... ";
$IPT -A INPUT -i lo -j ACCEPT > /dev/null 2>&1 && $IPT -A OUTPUT -o lo
-j ACCEPT > /dev/null 2>&1 && printf "OK\n" || printf "FALLÓ\n";

# PERMITIMOS CONEXIONES YA ESTABLECIDAS
printf "* Permitiendo conexiones YA establecidas ... ";
$IPT -A INPUT -i $EXT_IF -p all -m state --state ESTABLISHED,RELATED -j
ACCEPT > /dev/null 2>&1 && printf "OK\n" || printf "FALLÓ\n";


aqui lo mismo primero las permitis y luego las establecidas




# PERMITIMOS TODO EL TRÁFICO HACIA AFUERA
printf "* Permitiendo TODO el tráfico hacia afuera ... ";
$IPT -A OUTPUT -o $EXT_IF -j ACCEPT > /dev/null 2>&1 && printf "OK\n" ||
echo "FALLÓ\n";

# PERMITIMOS ALGUNAS CONEXIONES ENTRANTES
printf "* Permitiendo conexiones desde la intranet: ";

for i in ${PUERTOS_ABIERTOS[@]}
    do
        nombre_puerto=`echo $i | cut -d ":" -f 1`;
        puerto=`echo $i | cut -d ":" -f 2`;
        $IPT -A INPUT -i $EXT_IF -s ${LAN} -d $IP -p tcp --dport
${puerto} --syn -m state --state NEW -j ACCEPT > /dev/null 2>&1 &&
printf "${nombre_puerto} " || printf "¬${nombre_puerto} ";
    done
printf "\n\n";
--- END SCRIPT

Muchas gracias....

--
.---------------------------------------------------------------------.
| Miguel J. Jiménez                                                   |
| Programador Senior                                                  |
| Área de Internet/XSL/PHP                                            |
| migueljose.jimenez@isotrol.com                                      |
:---------------------------------------------------------------------:
| ISOTROL, S.A.                                                       |
| Edificio BLUENET, Avda. Isaac Newton nº3, 4ª planta.                |
| Parque Tecnológico Cartuja '93, 41092 Sevilla (ESP).                |
| Teléfono: +34 955 036 800 - Fax: +34 955 036 849                    |
| http://www.isotrol.com                                              |
:---------------------------------------------------------------------:
| "It's kind of like trying to sing the lyrics to The Macarena. You   |
| can send out the words but you have no idea what you're singing."   |
|  Ronald McKay, Stargate Atlantis (3x12) - Echoes                    |
'---------------------------------------------------------------------'





--
MrIX
Linux user number 412793.
http://counter.li.org/

las grandes obras,
las sueñan los santos locos,
las realizan los luchadores natos,
las aprovechan los felices cuerdo,
y las critican los inútiles crónicos,

yo no fui, seguro que es mas inteligente.



Reply to: