Step by step Setup and Configure Squid Proxy Server on Fedora Core.
The article below show the step by step to setup and configure SQUID proxy serve on Fedora core with screenshot and SQUID configuration example.
Network configuration scenario:
Setp 1:To backup the Squid configuration directory:
[root@cempakasari ~]# cp -pr /etc/squid/ /etc/squid.bak
[root@cempakasari ~]#
Backup the squid.conf file:
[root@cempakasari ~]# cp -pr /etc/squid/squid.conf /etc/squid/squid.conf.bak
[root@cempakasari ~]#
Setp 2:Edit the squid.conf, the Squid Cache Proxy configuration file.
1. Open the squid config file (squid.conf) that is located on the /etc/squid directory with your own choice of text editor.
[root@linux fedora]# vi /etc/squid/squid.conf
or you can use the gedit program...
[root@linux fedora]# gedit /etc/squid/squid.con
On this project, we setup (configure) our Squid proxy to bind with the internal Ethernet card which is using internal IP 10.2.0.5 and listen on port 8080 on that internal IP address. With this configuration, Squid should only visible and listen to our internal address only.
Change the address to fit your network layout.
# NETWORK OPTIONS
........................
#Default:
# http_port 3128
http_port 10.2.0.5:8080
Setp 3:Scroll down the page and find # TAG: cache_mem (bytes), To increase the Squid cache memory capacity, edit the default setting and put the appropriate memory size base on your system capabilities. The example below show that the Squid cache memory setting increase up to 256 MB. Take note that, before you change this setting make sure your hardware can support the size of memory that you specify here.
# OPTIONS WHICH AFFECT THE CACHE SIZE
# -----------------------------------
# TAG: cache_mem (bytes)
# NOTE: THIS PARAMETER DOES NOT SPECIFY THE MAXIMUM PROCESS SIZE.
# IT ONLY PLACES A LIMIT ON HOW MUCH ADDITIONAL MEMORY SQUID WILL
# USE AS A MEMORY CACHE OF OBJECTS. SQUID USES MEMORY FOR OTHER
# THINGS AS WELL. SEE THE SQUID FAQ SECTION 8 FOR DETAILS.
#
# 'cache_mem' specifies the ideal amount of memory to be used
# for:
# * In-Transit objects
# * Hot Objects
# * Negative-Cached objects
------- +++++ ---------------------------
#Default:
# cache_mem 8 MB
cache_mem 256 MB
4. Then find tag # TAG: cache_dir, then increase the size of cache directory to 2000 MB, also make sure that you have enough
disk space before you change the size value.
# LOGFILE PATHNAMES AND CACHE DIRECTORIES
# -----------------------------------------------------------------------------
# TAG: cache_dir
# Usage:
#
# cache_dir Type Directory-Name Fs-specific-data [options]
#
------- +++++ ---------------------------
#
#Default:
# cache_dir ufs /var/spool/squid 100 16 256
cache_dir ufs /var/spool/squid 2000 16 256
Setp 4:Adjust the list of DNS name servers. Squid cache proxy used this list of DNS servers to query domain name.
# TAG: dns_nameservers
# Use this if you want to specify a list of DNS name servers
# (IP addresses) to use instead of those given in your
# /etc/resolv.conf file.
# On Windows platforms, if no value is specified here or in
# the /etc/resolv.conf file, the list of DNS name servers are
# taken from the Windows registry, both static and dynamic DHCP
# configurations are supported.
#
# Example: dns_nameservers 10.0.0.1 192.172.0.4
#
#Default:
# none
dns_nameservers 203.106.93.91 161.142.227.17 192.228.128.16 201.188.0.16
Setp 5:Add required port to "Acess Control List". This example show that the port number 2083 port is add to safe_ports list.
# ACCESS CONTROLS
# ---------------------------
----------- **** +++++
#Examples:
#acl macaddress arp 09:00:2b:23:45:67
#acl myexample dst_as 1241
#acl password proxy_auth REQUIRED
#acl fileupload req_mime_type -i ^multipart/form-data$
#acl javascript rep_mime_type -i ^application/x-javascript$
#
#Recommended minimum configuration:
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 2083 443 563
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 2083 443 563 # https, snews
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
acl CONNECT method CONNECT
You can enter your own rules:# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
# Example rule allowing access from your local networks. Adapt
# to list your (internal) IP networks from where browsing should
# be allowed
#acl our_networks src 192.168.1.0/24 192.168.2.0/24
#http_access allow our_networks
acl our_networks src 172.16.160.0/24 172.16.161.0/24 172.16.162.0/24 172.16.163.0/24 172.16.164.0/24 172.16.165.0/24 172.16.166.0/24 172.16.167.0/24 172.16.168.0/24 172.16.169.0/24 172.16.170.0/24
acl bad_url dstdomain "/etc/squid/bad-sites.squid"
http_access allow our_networks
http_access deny bad_url
To allow FTP request from client.
# TAG: always_direct
# Usage: always_direct allowdeny [!]aclname ...
#
# Here you can use ACL elements to specify requests which should
# ALWAYS be forwarded by Squid to the origin servers without using
# any peers. For example, to always directly forward requests for
# local servers ignoring any parents or siblings you may have use
# something like:
#
# acl local-servers dstdomain my.domain.net
# always_direct allow local-servers
#
# To always forward FTP requests directly, use
#
# acl FTP proto FTP
# always_direct allow FTP
+++++++++++++++++++++
#
#Default:
# none
acl FTP proto FTP
always_direct allow FTP
In order to make sure that the configuration and your Squid proxy server running smoothly, test to start Squid proxy server in debugging mode; The command example below show the step by step to create the Squid cache directory and then running Squid proxy server in debugging mode.
1. Create squid cache directory by issuing this command:
[root@linux fedora]# /usr/sbin/squid -z
2006/03/16 10:33:00 Creating Swap Directories
2. Then test run your Squid cache proxy by running Squid in debug-mode
[root@linux fedora]# /usr/sbin/squid -NCd1
Ctrl + C to stop.
Output
2006/03/16 10:43:22 Preparing for shutdown after 39 requests
2006/03/16 10:43:22 Waiting 0 seconds for active connections to finish
2006/03/16 10:43:22 FD 11 Closing HTTP connection
2006/03/16 10:43:22 FD 12 Closing HTTP connection
2006/03/16 10:43:24 Shutting down...
2006/03/16 10:43:24 FD 13 Closing ICP connection
2006/03/16 10:43:24 Closing unlinkd pipe on FD 9
2006/03/16 10:43:24 storeDirWriteCleanLogs: Starting...
2006/03/16 10:43:25 Finished. Wrote 7796 entries.
2006/03/16 10:43:25 Took 0.1 seconds (89056.4 entries/sec).
Use the following command to start and stop Squid.
[root@linux fedora]# /sbin/service squid start
[root@linux fedora]# /sbin/service squid stop
To make sure Squid automatic start after the system reboot, use the chkconfig command to On Squid on runlevel 3 and 5. (Setting of automatic start on runlevel 3 and 5)
[root@linux fedora]# /sbin/chkconfig --level 35 squid on
(Confirmation of automatic start)
[root@linux fedora]# /sbin/chkconfig --list squid
squid 0:off 1: off 2: off 3: on 4: off 5:on 6: off