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

Re: IPTABLES y NAT



Tu salida a internet, esta en eth1 o en ppp0?


> Hola ocurre que tengo el siguiente inconveniente, no logro que la lan
salga
> a Internet con el siguiente script, que hago mal, los servicios que tengo
> habilitados  son www y ssh:
>
> #!/bin/sh
> IPTABLES=/sbin/iptables
> DNS1=200.72.1.5
> DNS2=200.72.1.11
>   IINTERFACE=eth0
> OINTERFACE=eth1
>
> ### cargamos módulos necesarios
> /sbin/modprobe ip_tables
> /sbin/modprobe ip_conntrack
> /sbin/modprobe iptable_filter
> /sbin/modprobe iptable_mangle
> /sbin/modprobe iptable_nat
> /sbin/modprobe ipt_LOG
> /sbin/modprobe ipt_limit
> /sbin/modprobe ipt_MASQUERADE
> /sbin/modprobe ipt_state
>
> ### Borramos tablas
> $IPTABLES -F
> $IPTABLES -t nat -F
> $IPTABLES -t mangle -F
> $IPTABLES -X
> $IPTABLES -t nat -X
> $IPTABLES -t mangle -X
>
> ### Ponemos las reglas por defecto a las tablas
> $IPTABLES -P FORWARD DROP
> $IPTABLES -P INPUT DROP
> $IPTABLES -P OUTPUT DROP
>
>
>   $IPTABLES -A INPUT -s 192.168.1.0/24 -i eth1 -j ACCEPT
> echo > 1 /proc/sys/net/ipv4/ip_forward
> $IPTABLES -t nat -A POSTROUTING -s 192.168.1.0/24 -O ppp0 -j MASQUERADE
>
> ### Creamos chains de estado
> $IPTABLES -N allowed-connection
> $IPTABLES -F allowed-connection
> $IPTABLES -A allowed-connection -m state --state ESTABLISHED,RELATED -j
> ACCEPT
> $IPTABLES -A allowed-connection -i ppp0 -m limit -j LOG --log-prefix
> #"Paquete incorrecto desde ${IINTERFACE}:"
> $IPTABLES -A allowed-connection -j DROP
>
> ### Tráfico ICMP
> $IPTABLES -N icmp_allowed
> $IPTABLES -F icmp_allowed
> $IPTABLES -A icmp_allowed -m state --state NEW -p icmp --icmp-type
> time-exceeded -j ACCEPT
> $IPTABLES -A icmp_allowed -m state --state NEW -p icmp --icmp-type
> destination-unreachable -j ACCEPT
> $IPTABLES -A icmp_allowed -p icmp -j LOG --log-prefix
> #"Tráfico incorrecto:"
> $IPTABLES -A icmp_allowed -p icmp -j DROP
>
> ### Tráfico que entra
> $IPTABLES -N allow-ssh-traffic-in
> $IPTABLES -F allow-ssh-traffic-in
> $IPTABLES -A allow-ssh-traffic-in -p tcp --sport ssh -j ACCEPT
>
> ### Tráfico que sale
> $IPTABLES -N allow-ssh-traffic-out
> $IPTABLES -F allow-ssh-traffic-out
> $IPTABLES -A allow-ssh-traffic-out -p tcp --dport ssh -j ACCEPT
>
> $IPTABLES -N allow-dns-traffic-out
> $IPTABLES -F allow-dns-traffic-out
> $IPTABLES -A allow-dns-traffic-out -p udp -d $DNS1 --dport domain -j
ACCEPT
> $IPTABLES -A allow-dns-traffic-out -p udp -d $DNS2 --dport domain -j
ACCEPT
>
> $IPTABLES -N allow-www-traffic-out
> $IPTABLES -F allow-www-traffic-out
> $IPTABLES -A allow-www-traffic-out -p tcp --dport www -j ACCEPT
> $IPTABLES -A allow-www-traffic-out -p tcp --dport https -j ACCEPT
>
> #### Detección de escaneos
> $IPTABLES -N check-flags
> $IPTABLES -F check-flags
> $IPTABLES -A check-flags -p tcp --tcp-flags ALL FIN,URG,PSH -m
limit --limit
> 5/minute -j LOG --log-level alert --log-prefix "NMAP-XMAS:"
> $IPTABLES -A check-flags -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
> $IPTABLES -A check-flags -p tcp --tcp-flags ALL ALL -m limit --limit
> 5/minute -j LOG --log-level 1 --log-prefix "XMAS:"
> $IPTABLES -A check-flags -p tcp --tcp-flags ALL ALL -j DROP
> $IPTABLES -A check-flags -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -m
limit
> --limit 5/minute -j LOG --log-level 1 --log-prefix "XMAS-PSH:"
> $IPTABLES -A check-flags -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j
DROP
> $IPTABLES -A check-flags -p tcp --tcp-flags ALL NONE -m limit --limit
> 5/minute -j LOG --log-level 1 --log-prefix "NULL_SCAN:"
> $IPTABLES -A check-flags -p tcp --tcp-flags ALL NONE -j DROP
> $IPTABLES -A check-flags -p tcp --tcp-flags SYN,RST SYN,RST -m
limit --limit
> 5/minute -j LOG --log-level 5 --log-prefix "SYN/RST:"
> $IPTABLES -A check-flags -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
> $IPTABLES -A check-flags -p tcp --tcp-flags SYN,FIN SYN,FIN -m
limit --limit
> 5/minute -j LOG --log-level 5 --log-prefix "SYN/FIN:"
> $IPTABLES -A check-flags -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
>
> ### Protección flooding
> $IPTABLES -N delay-flags
> $IPTABLES -F delay-flags
> $IPTABLES -A delay-flags -m limit --limit 1/second -p tcp --tcp-flags ALL
> RST -j ACCEPT
> $IPTABLES -A delay-flags -m limit --limit 1/second -p tcp --tcp-flags ALL
> FIN -j ACCEPT
> $IPTABLES -A delay-flags -m limit --limit 1/second -p tcp --tcp-flags ALL
> SYN -j ACCEPT
>
> ### Aplicamos y añadimos estados inválidos a los chains
> $IPTABLES -A INPUT -m state --state INVALID -j DROP
> $IPTABLES -A INPUT -j icmp_allowed
> $IPTABLES -A INPUT -j check-flags
> $IPTABLES -A INPUT -j delay-flags
> $IPTABLES -A INPUT -i lo -j ACCEPT
> $IPTABLES -A INPUT -j allow-ssh-traffic-in
> $IPTABLES -A INPUT -j allowed-connection
>
> $IPTABLES -A FORWARD -m state --state INVALID -j DROP
> $IPTABLES -A FORWARD -j icmp_allowed
> $IPTABLES -A FORWARD -j check-flags
> $IPTABLES -A FORWARD -o lo -j ACCEPT
> $IPTABLES -A FORWARD -j allow-ssh-traffic-in
> $IPTABLES -A FORWARD -j allow-www-traffic-out
> $IPTABLES -A FORWARD -j allowed-connection
> $IPTABLES -A FORWARD -i eth1 -j ACCEPT
>
> $IPTABLES -A OUTPUT -m state --state INVALID -j DROP
> $IPTABLES -A OUTPUT -j icmp_allowed
> $IPTABLES -A OUTPUT -j check-flags
> $IPTABLES -A OUTPUT -o lo -j ACCEPT
> $IPTABLES -A OUTPUT -j allow-ssh-traffic-out
> $IPTABLES -A OUTPUT -j allow-dns-traffic-out
> $IPTABLES -A OUTPUT -j allow-www-traffic-out
> $IPTABLES -A OUTPUT -j allowed-connection
>
>
>      Haber este script lo consegui en Internet, basicamente lo unico que
> necesito es que me funcione como gateway y dar funcionalidad a los puertos
> ssh y www por el momento ah importante protejer el puerto 5432
(Postgresql),
> ya que las conecciones a la base de datos las hago a traves de ssh como
una
> tuberia.
>
> Agradecere su ayuda.
>
> Fernando
>
> _________________________________________________________________
> MSN Amor: busca tu ½ naranja http://latam.msn.com/amor/
>
>
> -- 
> To UNSUBSCRIBE, email to debian-user-spanish-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact
listmaster@lists.debian.org
>



Reply to: