A proxy server is a server  that acts as an intermediary for requests from clients seeking resources from other servers. A client connects to the proxy server, requesting some service, such as a file, connection, web page, or other resource, available from a different server.

The proxy server evaluates the request according to its filtering rules. For example, it may filter traffic by IP address or protocol. If the request is validated by the filter, the proxy provides the resource by connecting to the relevant server and requesting the service on behalf of the client.

Transparent Proxies

An intercepting proxy ( or transparent proxy) combines a proxy server with a gateway or router (commonly with NAT capabilities). Connections made by client browsers through the gateway are diverted to the proxy without client-side configuration.
“A ‘transparent proxy’ is a proxy that does not modify the request or response beyond what is required for proxy authentication and identification”.

Main benefit of setting transparent proxy is you do not have to setup up individual browsers to work with proxies.


ii) Eth0: IP:
iii) Eth1: IP: ( network.
iv) OS: CentOS 5.4

Eth0 connected to internet and eth1 connected to local lan i.e. system act as router.

Server Configuration

  • Step #1 : Squid configuration so that it will act as a transparent proxy
  • Step #2 : Iptables configuration
    • a) Configure system as router
    • b) Forward all http requests to 3128 (DNAT)
  • Step #3: Run scripts and start squid service

Configure squid  by adding following directives to file:

# vi /etc/squid/squid.conf

Modify or add following squid directives:

http_port 80 vhost

  • http_port 80 vhost: Squid as an httpd accelerator and 80 is port you want to act as a proxy

Here is the complete listing of squid.conf for your reference

[root@gateway squid]# cat /etc/squid/squid.conf
acl all src
acl manager proto cache_object
acl localhost src
acl to_localhost dst
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
acl bad dstdomain “/etc/squid/bad-sites.acl”
http_access allow !bad
acl our_networks src
#http_access allow our_networks
#http_access allow localhost
acl ftp proto FTP
http_access allow ftp
http_access deny all
http_reply_access allow all
icp_access allow all
#hicp_access allow all
http_port transparent
hierarchy_stoplist cgi-bin ?
cache_mem 128 MB
cache_dir ufs /home/squid 512 16 256
access_log /home/log/squid/access.log squid
error_log /home/log/squid/error.log squid
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern .               0       20%     4320
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
visible_hostname gateway
http_port 80 vhost
coredump_dir /home/spool/squid

Iptables configuration

Next, add following rules to forward all http requests (coming to port 80) to the Squid server port 3128 :
# iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j DNAT --to
# iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128

Start or Restart the squid:
# /etc/init.d/squid restart
# chkconfig squid on

Desktop / Client computer configuration

Point all desktop clients to your eth1 IP address ( as Router/Gateway (use DHCP to distribute this information). You do not have to setup up individual browsers to work with proxies.

How do I test my squid proxy is working correctly?

See access log file /var/log/squid/access.log:
# tail -f /var/log/squid/access.log
Above command will monitor all incoming request and log them to /var/log/squid/access_log file. Now if somebody accessing a website through browser, squid will log information.

Posted in: Linux.
Last Modified: November 12, 2013

Leave a reply