[CentOS-es] Iptables y Squid en una misma PC

Maximo Mosalvo maxnux en yahoo.com.ar
Mie Nov 14 19:27:17 UTC 2007


Daniel Lopez wrote:
> Hola, tengo implementado un Servidor CentOS 5 el cual tiene levantado el
> squid y SSH y funciona bien, es decir controlo la salida a Internet de todas
> las PCs de mi LAN. El tema es que necesito levantar un firewall con reglas
> iptables para poder controlar mejor los accesos externos e internos. Los
> scripts que utilizo los uso de http://www.linuxguruz.com/iptables/  incluso
> e levantado anteriormente un firewall (iptables) y proxy (squid) pero en PCs
> diferentes y funcionan OK.
>
> Para este caso necesito que funcionen ambos en una misma PC, aqui les copio
> mis reglas de iptables (no la del squid porque este funciona OK). El
> problema es que con mis reglas actuales cuando activo el FW pierdo la
> conexion con el proxy y las PCs no pueden navegar y el iptraf me muestra que
> las conexiones si llegan a LAN_IFACE pero por INET_IFACE no sale nada. Como
> observacion diria que si en el lugar de las reglas DEJAR PASAR EL PROXY
> utilizo estas :
>
> $IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
> $IPTABLES -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
> $IPTABLES -A INPUT -i $LAN_IFACE -p tcp --dport 3128 -m state --state NEW -j
> ACCEPT
> $IPTABLES -A INPUT -i $LAN_IFACE -p icmp --icmp-type echo-request -j ACCEPT
> $IPTABLES -A OUTPUT -o $INET_IFACE -p udp --dport 53 -m state --state NEW -j
> ACCEPT
> $IPTABLES -A OUTPUT -o $INET_IFACE -p tcp --dport 53 -m state --state NEW -j
> ACCEPT
> $IPTABLES -A OUTPUT -o $INET_IFACE -p tcp --dport 80 -m state --state NEW -j
> ACCEPT
> $IPTABLES -A OUTPUT -o $INET_IFACE -p tcp --dport 443 -m state --state
> NEW -j ACCEPT
>   
Y que reglas de FORWARD estas usando ?

> Las PCs si pueden navegar, pero todas ellas pueden acceder al SSH de mi
> Servidor (obvio ya que se esta indicando que sea aceptado todo lo que entre
> y salga). Por lo que deduzco debo reemplazar esas reglas por algunas en la
> cual definir : Todo lo que venga de mi LAN vaya al puerto 3128 y salga de
> el, debe ser enviado a Internet, y al volver debe hacer el camino de
> regreso. Cuales serian esas reglas? *les pido ayuda ya que e probado varias
> reglas y me e estancado en ese punto, quizas sea algo sencillo :(
>
> # description: Reglas que permiten la salida a travez del Proxy y activan el
> FW
>
> echo Definiendo variables
>
> LAN_IP=
> LAN_IP_RANGE=
> LAN_BCAST_ADRESS=
> LAN_IFACE=
>
> LO_IFACE=
> LO_IP=
>
> INET_IP=
> INET_IFACE=
>
> LAN_IT_IP=
> PROXY_IP=
>
> ###########################################################################
> #
> # IPTables Configuration.
> #
>
> IPTABLES="/sbin/iptables"
>
> ###########################################################################
> #
> # Module loading.
> #
>
> #
> # Needed to initially load modules
> #
>
> /sbin/depmod -a
>
> #
> # Adds some iptables targets like LOG, REJECT and MASQUARADE.
> #
>
> #/sbin/modprobe ip_conntrack
> #/sbin/modprobe ip_tables
> #/sbin/modprobe iptable_filter
> #/sbin/modprobe iptable_mangle
> #/sbin/modprobe iptable_nat
> /sbin/modprobe ipt_LOG
> /sbin/modprobe ipt_MASQUERADE
>
> #/sbin/modprobe ipt_REJECT
> #/sbin/modprobe ipt_MASQUERADE
>
> #
> # Support for owner matching
> #
> #/sbin/modprobe ipt_owner
>
> #
> # Support for connection tracking of FTP and IRC.
> #
> #/sbin/modprobe ip_conntrack_ftp
> #/sbin/modprobe ip_conntrack_irc
>
> ###########################################################################
> #
> # Enable ip_forward if you have two or more networks, including the
> # Internet, that needs forwarding of packets through this box. This is
> # critical since it is turned off as default in Linux.
> #
>
> echo "1" > /proc/sys/net/ipv4/ip_forward
>
> #
> # Dynamic IP users:
> #
>
> #echo "1" > /proc/sys/net/ipv4/ip_dynaddr
>
> echo ......................................................................
> echo Limpiando configuracion
> echo ......................................................................
>
> $IPTABLES -F
> $IPTABLES -X
> $IPTABLES -Z
>
> echo ......................................................................
> echo Reglas por defecto
> echo ......................................................................
>
> $IPTABLES -P INPUT DROP
> $IPTABLES -P OUTPUT DROP
> $IPTABLES -P FORWARD DROP
>
> echo Configuracion accesos
>
> $IPTABLES -A INPUT -p TCP -i $LAN_IFACE -s $LAN_IT_IP -d $LAN_IP --dport
> 22 -j ACCEPT
> $IPTABLES -A OUTPUT -p TCP -o $LAN_IFACE -s $LAN_IP -d $LAN_IT_IP --sport
> 22 -j ACCEPT
>
> echo DEJAR PASAR EL PROXY
>
> $IPTABLES -A INPUT -p TCP -i $LAN_IFACE -d $PROXY_IP --dport 3128 -j ACCEPT
>
> $IPTABLES -A OUTPUT -p TCP -o $INET_IFACE -s $INET_IP --dport 80 -j ACCEPT
> $IPTABLES -A OUTPUT -p TCP -o $INET_IFACE -s $INET_IP --dport 443 -j ACCEPT
> $IPTABLES -A OUTPUT -p UDP -o $INET_IFACE -s $INET_IP --dport 53 -j ACCEPT
>
> #
> # The allowed chain for TCP connections
> #
>
> $IPTABLES -N allowed
> $IPTABLES -A allowed -p TCP --syn -j ACCEPT
> $IPTABLES -A allowed -p TCP -m state --state ESTABLISHED,RELATED -j ACCEPT
> $IPTABLES -A allowed -p TCP -j DROP
>
> #
> # ICMP rules
> #
>
> $IPTABLES -N icmp_packets
>
> # Changed rules totally
>
> $IPTABLES -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j ACCEPT
> $IPTABLES -A icmp_packets -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT
>
> #
> # bad_tcp_packets chain
> #
> # Take care of bad TCP packets that we don't want.
> #
>
> $IPTABLES -N bad_tcp_packets
> $IPTABLES -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j LOG \
> --log-prefix "New not syn:"
> $IPTABLES -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP
>
> #
> # Do some checks for obviously spoofed IP's
> #
>
> $IPTABLES -A bad_tcp_packets -i $INET_IFACE -s 192.168.0.0/16 -j DROP
> $IPTABLES -A bad_tcp_packets -i $INET_IFACE -s 10.0.0.0/8 -j DROP
> $IPTABLES -A bad_tcp_packets -i $INET_IFACE -s 172.16.0.0/12 -j DROP
>
> echo ......................................................................
> echo Tabla NAT : POSTROUTING
> echo ......................................................................
>
> #
> # Enable simple IP Forwarding and Network Address Translation
> #
>
> $IPTABLES -t nat -A POSTROUTING -o $INET_IFACE -j SNAT --to-source $INET_IP
>
> echo ......................................................................
> echo Tabla NAT : PREROUTING
> echo ......................................................................
>
> #
> # Bad TCP packets we don't want
> #
>
> $IPTABLES -A FORWARD -p tcp -j bad_tcp_packets
>
> #
> #Log all packets reaching here
> #
>
> $IPTABLES -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j LOG \
> --log-level DEBUG --log-prefix "IPT FORWARD packet died: "
>
> ##########################
> # INPUT chain
> #
> # Bad TCP packets we don't want.
> #
>
> $IPTABLES -A INPUT -p tcp -j bad_tcp_packets
>
> #
> # Rules for incoming packets from the internet.
> #
>
> $IPTABLES -A INPUT -p ICMP -i $INET_IFACE -j icmp_packets
> #$IPTABLES -A INPUT -p TCP -i $INET_IFACE -j tcp_packets
> #$IPTABLES -A INPUT -p UDP -i $INET_IFACE -j udpincoming_packets
>
> #
> # Rules for special networks not part of the Internet
> #
>
> $IPTABLES -A INPUT -p ALL -i $LAN_IFACE -d $LAN_IP -j ACCEPT
> $IPTABLES -A INPUT -p ALL -i $LAN_IFACE -d $LAN_BCAST_ADRESS -j ACCEPT
> $IPTABLES -A INPUT -p ALL -i $LO_IFACE -s $LO_IP -j ACCEPT
> $IPTABLES -A INPUT -p ALL -i $LO_IFACE -s $LAN_IP -j ACCEPT
> $IPTABLES -A INPUT -p ALL -i $LO_IFACE -s $INET_IP -j ACCEPT
> #$IPTABLES -A INPUT -p ALL -i $LAN_IFACE -s $LAN_IP_RANGE -j ACCEPT
>
> $IPTABLES -A INPUT -p ALL -d $INET_IP -m state --state ESTABLISHED,RELATED \
> -j ACCEPT
> $IPTABLES -A INPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
> --log-level DEBUG --log-prefix "IPT INPUT packet died: "
>
> ###############################
> # OUTPUT chain
> #
> #
> # Bad TCP packets we don't want.
> #
>
> $IPTABLES -A OUTPUT -p tcp -j bad_tcp_packets
>
> #
> # Special OUTPUT rules to decide which IP's to allow.
> #
>
> $IPTABLES -A OUTPUT -p ALL -o LO_IFACE -s $LO_IP -j ACCEPT
> $IPTABLES -A OUTPUT -p ALL -o LAN_IFACE -s $LAN_IP -j ACCEPT
> $IPTABLES -A OUTPUT -p ALL -o INET_IFACE -s $INET_IP -j ACCEPT
>
> #
> # Log weird packets that don't match the above.
> #
>
> $IPTABLES -A OUTPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
> --log-level DEBUG --log-prefix "IPT OUTPUT packet died: "
>
> _______________________________________________
> CentOS-es mailing list
> CentOS-es en centos.org
> http://lists.centos.org/mailman/listinfo/centos-es
>
>   


-- 
#-----------------------------------------------------------------------------------------------------------
-Con linux no siempre Ganas :(

Charla entra amigote y la bruja
Amigote: Che asi que lo enganchaste nomas!!!! como lo convenciste
la bruja: Facil me disfrace de Pinguino y acepto enceguida ;)
#-----------------------------------------------------------------------------------------------------------






























Más información sobre la lista de distribución CentOS-es