As the root user, install the squid package. Run rpm -q squid
to see if the squid package is installed. If it is not installed, run yum install squid
as the root user to install it.
Edit the main configuration file, /etc/squid/squid.conf
and confirm that the cache_dir
directive is uncommented and looks similar to the following:
cache_dir ufs /var/spool/squid 100 16 256
This line specifies the default settings for the cache_dir
directive to be used in this example; it consists of the Squid storage format (ufs), the directory on the system where the cache resides (/var/spool/squid), the amount of disk space in megabytes to be used for the cache (100), and finally the number of first-level and second-level cache directories to be created (16 and 256 respectively).
In the same configuration file, make sure the http_access allow localnet
directive is uncommented. This allows traffic from the localnet
ACL which is automatically configured in a default installation of Squid on Red Hat Enterprise Linux. It will allow client machines on any existing RFC1918 network to have access through the proxy, which is sufficient for this simple example.
In the same configuration file, make sure the visible_hostname
directive is uncommented and is configured to the hostname of the machine. The value should be the fully qualified domain name (FQDN) of the host:
visible_hostname squid.example.com
As the root user, run service squid start
to start squid
. As this is the first time squid
has started, this command will initialise the cache directories as specified above in the cache_dir
directive and will then start the squid
daemon. The output is as follows if squid
starts successfully:
# /sbin/service squid start
init_cache_dir /var/spool/squid... Starting squid: . [ OK ]
Confirm that the squid
process ID (PID) has started as a confined service, as seen here by the squid_var_run_t
value:
# ls -lZ /var/run/squid.pid
-rw-r--r--. root squid unconfined_u:object_r:squid_var_run_t:s0 /var/run/squid.pid
At this point, a client machine connected to the localnet
ACL configured earlier is successfully able to use the internal interface of this host as its proxy. This can be configured in the settings for all common web browsers, or system-wide. Squid is now listening on the default port of the target machine (TCP 3128), but the target machine will only allow outgoing connections to other services on the Internet via common ports. This is a policy defined by SELinux itself. SELinux will deny access to non-standard ports, as shown in the next step:
When a client makes a request using a non-standard port through the Squid proxy such as a website listening on TCP port 10000, a denial similar to the following is logged:
SELinux is preventing the squid daemon from connecting to network port 10000
To allow this access, the squid_connect_any
Boolean must be modified, as it is disabled by default. To turn the squid_connect_any
Boolean on, run the following command as the root user:
# setsebool -P squid_connect_any on
Do not use the -P
option if you do not want setsebool
changes to persist across reboots.
The client will now be able to access non-standard ports on the Internet as Squid is now permitted to initiate connections to any port, on behalf of its clients.