Este contenido no está disponible en el idioma seleccionado.

Chapter 19. Squid Caching Proxy


Squid is a high-performance proxy caching server for web clients, supporting FTP, Gopher, and HTTP data objects. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages.[17]
In Red Hat Enterprise Linux, the squid package provides the Squid Caching Proxy. Enter the following command to see if the squid package is installed:
~]$ rpm -q squid
package squid is not installed
Copy to Clipboard Toggle word wrap
If it is not installed and you want to use squid, use the yum utility as root to install it:
~]# yum install squid
Copy to Clipboard Toggle word wrap

19.1. Squid Caching Proxy and SELinux

When SELinux is enabled, Squid runs confined by default. Confined processes run in their own domains, and are separated from other confined processes. If a confined process is compromised by an attacker, depending on SELinux policy configuration, an attacker's access to resources and the possible damage they can do is limited. The following example demonstrates the Squid processes running in their own domain. This example assumes the squid package is installed:
  1. Run the getenforce command to confirm SELinux is running in enforcing mode:
    ~]$ getenforce
    Enforcing
    
    Copy to Clipboard Toggle word wrap
    The command returns Enforcing when SELinux is running in enforcing mode.
  2. Enter the following command as the root user to start the squid daemon:
    ~]# systemctl start squid.service
    Copy to Clipboard Toggle word wrap
    Confirm that the service is running. The output should include the information below (only the time stamp will differ):
    ~]# systemctl status squid.service
    squid.service - Squid caching proxy
       Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled)
       Active: active (running) since Mon 2013-08-05 14:45:53 CEST; 2s ago
    Copy to Clipboard Toggle word wrap
  3. Enter the following command to view the squid processes:
    ~]$ ps -eZ | grep squid
    system_u:system_r:squid_t:s0    27018 ?        00:00:00 squid
    system_u:system_r:squid_t:s0    27020 ?        00:00:00 log_file_daemon
    
    Copy to Clipboard Toggle word wrap
    The SELinux context associated with the squid processes is system_u:system_r:squid_t:s0. The second last part of the context, squid_t, is the type. A type defines a domain for processes and a type for files. In this case, the Squid processes are running in the squid_t domain.
SELinux policy defines how processes running in confined domains, such as squid_t, interact with files, other processes, and the system in general. Files must be labeled correctly to allow squid access to them.
When the /etc/squid/squid.conf file is configured so squid listens on a port other than the default TCP ports 3128, 3401 or 4827, the semanage port command must be used to add the required port number to the SELinux policy configuration. The following example demonstrates configuring squid to listen on a port that is not initially defined in SELinux policy configuration for it, and, as a consequence, the server failing to start. This example also demonstrates how to then configure the SELinux system to allow the daemon to successfully listen on a non-standard port that is not already defined in the policy. This example assumes the squid package is installed. Run each command in the example as the root user:
  1. Confirm the squid daemon is not running:
    ~]# systemctl status squid.service
    squid.service - Squid caching proxy
       Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled)
       Active: inactive (dead)
    
    Copy to Clipboard Toggle word wrap
    If the output differs, stop the process:
    ~]# systemctl stop squid.service
    Copy to Clipboard Toggle word wrap
  2. Enter the following command to view the ports SELinux allows squid to listen on:
    ~]# semanage port -l | grep -w -i squid_port_t
    squid_port_t                   tcp      3401, 4827
    squid_port_t                   udp      3401, 4827
    
    
    Copy to Clipboard Toggle word wrap
  3. Edit /etc/squid/squid.conf as root. Configure the http_port option so it lists a port that is not configured in SELinux policy configuration for squid. In this example, the daemon is configured to listen on port 10000:
    # Squid normally listens to port 3128
    http_port 10000
    
    Copy to Clipboard Toggle word wrap
  4. Run the setsebool command to make sure the squid_connect_any Boolean is set to off. This ensures squid is only permitted to operate on specific ports:
    ~]# setsebool -P squid_connect_any 0
    Copy to Clipboard Toggle word wrap
  5. Start the squid daemon:
    ~]# systemctl start squid.service
    Job for squid.service failed. See 'systemctl status squid.service' and 'journalctl -xn' for details.
    
    Copy to Clipboard Toggle word wrap
    An SELinux denial message similar to the following is logged:
    localhost setroubleshoot: SELinux is preventing the squid (squid_t) from binding to port 10000. For complete SELinux messages. run sealert -l 97136444-4497-4fff-a7a7-c4d8442db982
    
    Copy to Clipboard Toggle word wrap
  6. For SELinux to allow squid to listen on port 10000, as used in this example, the following command is required:
    ~]# semanage port -a -t squid_port_t -p tcp 10000
    Copy to Clipboard Toggle word wrap
  7. Start squid again and have it listen on the new port:
    ~]# systemctl start squid.service
    Copy to Clipboard Toggle word wrap
  8. Now that SELinux has been configured to allow Squid to listen on a non-standard port (TCP 10000 in this example), it starts successfully on this port.


[17] See the Squid Caching Proxy project page for more information.
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat