dotlinux blog

10 Useful “Squid Proxy Server” Interview Questions and Answers in Linux

Squid is a popular caching and forwarding HTTP web proxy. It has a wide range of uses, from improving web access speeds in an organization by caching frequently accessed content to acting as a security layer by filtering and controlling outgoing web traffic. In Linux environments, it's commonly deployed. This blog will present 10 interview questions related to Squid Proxy Server in Linux along with detailed answers to help you prepare for technical interviews.

2026-06

Table of Contents#

  1. What is Squid Proxy Server?
  2. How do you install Squid on a Linux system (e.g., Ubuntu or CentOS)?
  3. Explain the basic configuration file structure of Squid (squid.conf).
  4. How can you configure Squid to cache content?
  5. What are the different access control lists (ACLs) in Squid and how are they used?
  6. How do you set up authentication in Squid (e.g., using basic authentication)?
  7. Describe how Squid can be used for content filtering.
  8. What is the purpose of the cache_dir directive in squid.conf?
  9. How do you monitor Squid's performance (e.g., cache hit ratio)?
  10. Can you explain reverse proxy functionality in Squid?

1. What is Squid Proxy Server?#

Answer: Squid is a caching proxy for the Web (HTTP, HTTPS, FTP, etc.). It stores frequently requested web objects (like web pages, images) in its cache. When a client requests an object, Squid first checks its cache. If the object is present (cache hit), it serves it directly from the cache, reducing the load on the origin server and improving the client's access speed. It also acts as a forward proxy (client - side proxy) to control and manage outgoing web traffic from a network.

2. How do you install Squid on a Linux system (e.g., Ubuntu or CentOS)?#

Answer:

  • On Ubuntu:
    • Update the package list: sudo apt update
    • Install Squid: sudo apt install squid
  • On CentOS:
    • Enable the EPEL (Extra Packages for Enterprise Linux) repository (if not already enabled). For CentOS 7: sudo yum install epel-release
    • Install Squid: sudo yum install squid

After installation, the main configuration file is usually located at /etc/squid/squid.conf (may vary slightly depending on the distribution).

3. Explain the basic configuration file structure of Squid (squid.conf).#

Answer:

  • Comments: Lines starting with # are comments. They are used to document the configuration.
  • Directives:
    • HTTP Port: The http_port directive specifies the port on which Squid listens for incoming HTTP requests. For example, http_port 3128 (default port).
    • Cache Directory: The cache_dir directive defines where Squid stores its cached data. For example, cache_dir ufs /var/spool/squid 100 16 256 (where ufs is the storage format, /var/spool/squid is the directory, 100 is the size in MB, 16 is the number of first - level directories, and 256 is the number of second - level directories).
    • Access Control: There are directives like acl (Access Control List) to define rules for allowing or denying access. For example, acl localnet src 192.168.1.0/24 (defines an ACL for a local network). Then, http_access allow localnet (allows access from the defined local network).

4. How can you configure Squid to cache content?#

Answer:

  • Cache Directory Setup: As mentioned earlier, use the cache_dir directive. For example:
cache_dir ufs /var/spool/squid 100 16 256

This creates a cache directory with the specified size and structure.

  • Default Behavior: By default, Squid caches content. However, you can fine - tune caching behavior. For example, you can set the maximum object size to cache using the maximum_object_size directive. maximum_object_size 1024 KB (caches objects up to 1024 KB in size).

5. What are the different access control lists (ACLs) in Squid and how are they used?#

Answer:

  • Source ACL (src):
    • Example: acl internal_networks src 192.168.0.0/16 (defines an ACL for an internal network range). This is used to allow or deny access based on the source IP address of the client. For example, http_access allow internal_networks (allows clients from the defined internal networks to use the proxy).
  • Destination ACL (dst):
    • Example: acl restricted_sites dstdomain "/etc/squid/restricted_sites.txt" (where the file contains a list of domain names). Then, http_access deny restricted_sites (denies access to the domains in the list).
  • Time ACL (time):
    • Example: acl office_hours time MTWHF 09:00 - 17:00 (defines an ACL for office hours from Monday to Friday). You can then use it in http_access rules, e.g., http_access allow office_hours (allows access only during office hours).

6. How do you set up authentication in Squid (e.g., using basic authentication)?#

Answer:

  • Install the necessary packages:
    • On Ubuntu: sudo apt install squid - common (already installed with Squid in most cases).
    • On CentOS: sudo yum install httpd-tools (provides the htpasswd tool).
  • Create an authentication file:
    • Use htpasswd - c /etc/squid/passwd username (replace username with the actual username). This creates a password file.
  • Configure Squid:
    • Add the following to squid.conf:
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic realm Squid proxy - username
acl authenticated proxy_auth REQUIRED
http_access allow authenticated

The first line defines the authentication program and the password file. The second line sets the realm (a description for the authentication). The third line defines an ACL for authenticated users, and the fourth line allows access to authenticated users.

7. Describe how Squid can be used for content filtering.#

Answer:

  • URL Filtering:
    • Create a list of URLs (or patterns) in a text file. For example, /etc/squid/blocked_urls.txt with entries like *.pornsite.com or http://example.com/badpage.html.
    • Define an ACL: acl blocked_urls dstdomain "/etc/squid/blocked_urls.txt"
    • Deny access: http_access deny blocked_urls
  • MIME Type Filtering:
    • You can use the acl directive with the mime-type option. For example, acl video_mime mime-type video/* (defines an ACL for video MIME types). Then, http_access deny video_mime (denies access to video content).

8. What is the purpose of the cache_dir directive in squid.conf?#

Answer: The cache_dir directive is used to specify where Squid stores its cached data. It has several parameters:

  • Storage Format: Can be ufs (Unix File System - traditional format), aufs (Adaptive Replacement Cache File System - more efficient in some cases), etc.
  • Directory Path: The location on the disk where the cache will be stored (e.g., /var/spool/squid).
  • Cache Size: Defines the total size of the cache in megabytes (e.g., 100 for 100 MB).
  • Number of Directories: The number of first - level and second - level directories (e.g., 16 and 256 in the example cache_dir ufs /var/spool/squid 100 16 256). This helps in organizing the cached files for faster access.

9. How do you monitor Squid's performance (e.g., cache hit ratio)?#

Answer:

  • Using Squid's Built - in Tools:
    • squidclient: You can use commands like squidclient -h to get help. To check the cache hit ratio, you can use squidclient -p 3128 mgr:info (assuming Squid is running on port 3128). This will display various statistics, including the cache hit ratio. You can also use squidclient -p 3128 mgr:cache for more detailed cache manager statistics.
  • Logging and Analysis:
    • Squid logs to files (usually /var/log/squid/access.log). You can use tools like awk to analyze the logs. In Squid access logs, cache hit results are indicated by result codes (field $4) such as TCP_HIT, TCP_MISS, TCP_REFRESH_HIT, etc. For example, to count cache hits and misses:
awk '{if ($4 == "TCP_HIT") hits++; else if ($4 == "TCP_MISS") misses++} END {print "Hits:", hits, "Misses:", misses}' /var/log/squid/access.log

Then calculate the hit ratio as hit_ratio = hits / (hits + misses).

10. Can you explain reverse proxy functionality in Squid?#

Answer: In reverse proxy mode, Squid sits in front of web servers. When a client requests a web page, instead of the client directly accessing the origin web server, the request goes to Squid. Squid then forwards the request to the appropriate web server (based on its configuration). It can cache the responses from the web servers. This is useful for load balancing (distributing requests among multiple web servers), improving performance (by caching), and providing an additional security layer (hiding the internal web server IPs).

To configure Squid as a reverse proxy:

  • Set the http_port to listen on the external interface (e.g., http_port 80 accel vhost vport). The accel option enables acceleration (reverse proxy mode), vhost allows virtual hosting (multiple domains on one IP), and vport uses the same port as the web server (usually 80).
  • Define rules to map incoming requests to the appropriate web servers. For example, if you have a web server at 192.168.1.100:
cache_peer 192.168.1.100 parent 80 0 no-query originserver name=webserver1
acl webserver1 dstdomain www.example.com
http_access allow webserver1
cache_peer_access webserver1 allow all

Reference#

  • [Squid Documentation](http://www.squid - cache.org/Doc/)
  • Linux distribution - specific package management documentation (e.g., Ubuntu's apt documentation, CentOS's yum documentation)