Herramientas de usuario

Herramientas del sitio


servidores:squid:squid_basico

Squid: configuración de un servidor proxy

Por Félix Molinuevo, FMSI Sistemas de Informática

Pasos iniciales

El archivo de configuración por defecto de Squid es suficiente para obtener un proxy básico funcionando. Se deben realizar los siguientes cambios:

  1. Configurar el puerto:
    http_port 8080
  2. Configurar el tamaño máximo de los archivos a guardar en la caché. Esto por supuesto depende del tamaño que se le pueda asignar a la caché. Se estima aquí que la caché puede ser considerablemente grande, de entre 5 y 10GB. Archivos más grandes que el valor indicado aquí no serán guardados en la caché:
    maximum_object_size 153600 KB
  3. Configurar el tamaño de la caché y el tipo de almacenamiento. Usamos “aufs” porque hemos visto que Squid funciona mejor, creando varios threads para manejo de los archivos:
    cache_dir aufs /var/spool/squid 10240 16 256
  4. Especificar los DNSs a usar. Esto es útil cuando se desea usar otros DNSs distintos a los que están indicados en /etc/resolv.conf:
    dns_nameservers 172.16.11.1 172.16.11.2
  5. Configurar los patrones de refresco (refresh_pattern). Esto debe ser configurado con cuidado. Aquí se muestra una extensa lista de patrones de refresco, que pueden no ser ideales para todas las redes:
    # Debian
    refresh_pattern -i \.deb$   129600 100% 129600
    refresh_pattern -i \.gz$   129600 100% 129600
    refresh_pattern -i \.bz2$   129600 100% 129600
    
    # Imagenes
    refresh_pattern -i \.gif$ 14400 80% 43200
    refresh_pattern -i \.tiff?$ 14400 80% 43200
    refresh_pattern -i \.bmp$ 14400 80% 43200
    refresh_pattern -i \.jpe?g$ 14400 80% 43200
    refresh_pattern -i \.xbm$ 14400 80% 43200
    refresh_pattern -i \.png$ 14400 80% 43200
    refresh_pattern -i \.wrl$ 14400 80% 43200
    refresh_pattern -i \.ico$ 14400 80% 43200
    refresh_pattern -i \.pnm$ 14400 80% 43200
    refresh_pattern -i \.pbm$ 14400 80% 43200
    refresh_pattern -i \.pgm$ 14400 80% 43200
    refresh_pattern -i \.ppm$ 14400 80% 43200
    refresh_pattern -i \.rgb$ 14400 80% 43200
    refresh_pattern -i \.ppm$ 14400 80% 43200
    refresh_pattern -i \.rgb$ 14400 80% 43200
    refresh_pattern -i \.xpm$ 14400 80% 43200
    refresh_pattern -i \.xwd$ 14400 80% 43200
    refresh_pattern -i \.pict?$ 14400 80% 43200
    
    # Movies
    refresh_pattern -i \.mov$ 14400 80% 43200
    refresh_pattern -i \.mpe?g?$ 14400 80% 43200
    refresh_pattern -i \.avi$ 14400 80% 43200
    refresh_pattern -i \.qtm?$ 14400 80% 43200
    refresh_pattern -i \.viv$ 14400 80% 43200
    refresh_pattern -i \.swf$ 14400 80% 43200
    
    # Sounds
    refresh_pattern -i \.wav$ 14400 80% 43200
    refresh_pattern -i \.aiff?$ 14400 80% 43200
    refresh_pattern -i \.au$ 14400 80% 43200
    refresh_pattern -i \.ram?$ 14400 80% 43200
    refresh_pattern -i \.snd$ 14400 80% 43200
    refresh_pattern -i \.mid$ 14400 80% 43200
    refresh_pattern -i \.mp2$ 14400 80% 43200
    refresh_pattern -i \.mp3$ 14400 80% 43200
    
    # Archives
    refresh_pattern -i \.sit$ 14400 80% 43200
    refresh_pattern -i \.zip$ 14400 80% 43200
    refresh_pattern -i \.hqx$ 14400 80% 43200
    refresh_pattern -i \.exe$ 14400 80% 43200
    refresh_pattern -i \.bin$ 14400 80% 43200
    refresh_pattern -i \.arj$ 14400 80% 43200
    refresh_pattern -i \.lzh$ 14400 80% 43200
    refresh_pattern -i \.lha$ 14400 80% 43200
    refresh_pattern -i \.cab$ 14400 80% 43200
    refresh_pattern -i \.msi$ 14400 80% 43200
    refresh_pattern -i \.msp$ 14400 80% 43200
    refresh_pattern -i \.psf$ 14400 80% 43200
    refresh_pattern -i \.rar$ 14400 80% 43200
    refresh_pattern -i \.tar$ 14400 80% 43200
    refresh_pattern -i \.gz$ 14400 80% 43200
    refresh_pattern -i \.z$ 14400 80% 43200
    refresh_pattern -i \.a[0-9][0-9]$ 14400 80% 43200
    refresh_pattern -i \.r[0-9][0-9]$ 14400 80% 43200
    
    # Data files
    refresh_pattern -i \.txt$ 14400 80% 43200
    refresh_pattern -i \.pdf$ 14400 80% 43200
    refresh_pattern -i \.doc$ 14400 80% 43200
    refresh_pattern -i \.rtf$ 14400 80% 43200
    refresh_pattern -i \.tex$ 14400 80% 43200
    refresh_pattern -i \.latex$ 14400 80% 43200
    
    # Java-type objects
    refresh_pattern -i \.class$ 14400 80% 43200
    refresh_pattern -i \.js$ 14400 80% 43200
    refresh_pattern -i \.class$ 14400 80% 43200
    
    # Web-type objects
    refresh_pattern -i \.css$ 10 20% 4320
    refresh_pattern -i \.html?$ 10 20% 4320
    refresh_pattern \/$ 10 20% 4320
    
    
    # Para evitar problemas con scripts .do
    refresh_pattern -i \.do$ 0 0% 1440
    
    # Default
    refresh_pattern ^ftp:           1440    20%     10080
    refresh_pattern ^gopher:        1440    0%      1440
    refresh_pattern .               0       20%     4320
  6. Configurar una ACL que permita a los usuarios de la intranet hacer uso del proxy:
    acl intranet src 172.16.11.0/255.255.255.0
  7. Permitir el acceso a los usuarios que coincidan con la ACL previamente creada. Esta línea debe ser colocada inmediamente antes de la última o penúltima línea http_access del archivo original (eso se debe a que el orden de las mismas es importante):
    http_access allow intranet
  8. Con esto, Squid debería estar funcionando perfectamente como proxy de la intranet

Nota: es importante mencionar que Squid es un demonio muy complejo, que posee una enorme cantidad de opciones de configuración. Es probable que la configuración mostrada aquí sea sólo el principio de un largo trabajo de puesta a punto.

Autenticación contra PAM

  1. Instalar Squid
  2. Modificar el /etc/pam.conf/squid
    auth	required	/lib/security/pam_unix.so shadow nullok
    account	required	/lib/security/pam_unix.so 
  3. Modificar /etc/squid.conf
    auth_param basic program /usr/lib/squid/pam_auth
    auth_param basic children 5
    auth_param basic credentialsttl 2 hours
    auth_param basic realm Y si le marcai la user y la clave mocoreta
    
    # set up the acl name for user authentication
    acl localusers proxy_auth REQUIRED
    
    # set up the acl name for intranet (local network)
    acl intranet src 172.16.11.0/255.255.255.0
    
    # set up acl name for manager and localhost access
    acl manager proto cache_object
    acl localhost src 127.0.0.1/255.255.255.255
    
    # set up access to manager from localhost and deny manager access from anywhere else
    http_access allow manager localhostd
    http_access deny manager
    
    # set up all the denies for those not in the local network
    http_access deny !intranet
    # set up the user authentication
    http_access allow localusers
    # set up the allows for the local network
    http_access allow intranet
    # deny anything that passes beyond this point
    http_access deny all
  4. Chequear unas opciones de configuración que evitan que los usuarios compartan el mismo nombre de usuario y contraseña en 2 IPs diferentes

Autenticación contra Samba

Site filtering

This is just a quick view. There is much you can do here, you can also use http://www.squidguard.org to filter sites.

acl filter url_regex "/etc/squid/banned"
deny_info XANDER_ERR filter
http_access deny filter

stick partial site matches such as doubleclick into the file /etc/squid/banned to block urls containing these words in the titles.

banned file

The file XANDER_ERR is found at /etc/squid/errors/English/XANDER_ERR and is a standard html page giving a custom error message.

Have a look at the multitude of variables you can embed in the file.

Bandwidth control

  1. Agregar al squid.conf en sección DELAY POOL PARAMETERS
    delay_pools 1
    
    delay_class 1 1
    
    delay_access 1 allow intranet
    delay_access 1 deny all
    
    # Nota: intranet -> misma ACL configurada en las instrucciones anteriores
    
    delay_parameters 1 16000/16000

Nota1: 16000=16Kbps

Nota2: en este parámetro, hay muchas posibilidades. Probar según necesidades

Análisis de logs

Se puede visualizar el log de accesos con:

tail -F /var/log/squid/access.log | ccze -CA

O para analizarlos, convirtiendo los timestamps en fecha y hora, con Perl:

cat /var/log/squid/access.log | perl -p -e 's/^([0-9]*)/"[".localtime($1)."]"/e' | less

Bibliografía

servidores/squid/squid_basico.txt · Última modificación: 2019/07/10 12:24 por fmolinuevo