« Relay ControlSLAPD Service Control Script »

Squid Guard

07/26/04

Permalink 09:39:42 am, by admin Email , 1393 words   English (US)
Categories: Linux, Squid Proxy

Squid Guard

We'll start by installing Squid:

> cd /root
> wget http://www.squid-cache.org/Versions/v2/2.5/squid-2.5.STABLE3.tar.gz
> tar -xvzf squid-2.5.STABLE3.tar.gz
> cd squid-2.5.STABLE3
> ./configure
> make
> make install
> cd /root
> rm -rf squid-2.5.STABLE3
> mkdir archive
> mv squid-2.5.STABLE3.tar.gz archive

Squid is now installed at /usr/local/squid.

Notice that we use the "wget" command to download the software. Then we unpack and build the software. The build sequence is very typical for Linux packages - configure, make, make install.

We finish up by saving the distribution to /root/archive and removing the build
directory that is no longer needed.

Configuration for squid is pretty simple in the basic case. All configuration is
stored in a single file located at /usr/local/squid/etc/squid.conf.

The squid.conf file can be edited with your favoriate text editor. All though there
are hundreds of configuration options only a few are needed in a basic install. We made the following changes:

a. Find the line that looks like this (approx line 684):

  #cache_dir ufs /usr/local/squid/var/cache 100 16 256

Remove the "#" comment from the begining of the line and set the desired cache size and location:

  cache_dir ufs /usr/local/squid/var/cache 768 16 256

This defines a cache of not more then 768MB of disk storage.

b. Find the line that looks like this (approx line 1760):

  # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS

Below this line add the following lines:

  acl our_networks src 172.0.0.0/8
  http_access allow our_networks

  acl my_network src 127.0.0.1
  http_access allow my_network

The first new line defines an access control list (acl) called "our_networks" which 
includes the listed address ranges. The second line tells squid to accept connections
from the "our_networks" acl. The next two lines allow access through the loopback 
address.

c. Find the line (approx line 1973):

  # cache_effective_user nobody

Uncomment this line and change the username to squid. Then add a line to set the group:

  cache_effective_user squid
  cache_effective_group squid

For a basic setup that is all that is required in the way of configuration.

Next well prepare the cache directories and start the proxy server.

Type:

> chown --recursive squid.squid cache
> chown --recursive squid.squid logs
> /usr/local/squid/sbin/squid -z

This command may take several minutes to complete.

Now start the server with:

> /usr/local/squid/sbin/squid 

You can verify that squid is running by checking the log files:

> tail /var/log/messages

Now we can add a service control script to /etc/init.d. A suitable
script can be downloaded from Reliable Penguin:

> wget http://www.reliablepenguin.com/clients/misc/simplesquidguard.rh9.squid.service
> mv simplewquidguard.rh9.squid.service /etc/init.d/squid
> chmod 755 /etc/init.d/squid

And finally squid can be set to start on bootup:

> cd /etc/rc.d/rc5.d
> ln -s ../init.d/squid S25squid
> ln -s ../init.d/squid K25squid

Next we want to install SquidGuard but it requires the BerkeleyDB database 
library package so we'll install it first:

> cd /root
> wget http://www.sleepycat.com/update/snapshot/db-3.3.11.tar.gz
> tar -xvzf db-3.3.11.tar.gz
> cd db-3.3.11
> cd build_unix
> ../dist/configure
> make
> make install
> ldconfig
> cd /root
> rm -rf db-3.3.11
> mv db-3.3.11.tar.gz archive

The build procedure for BerkeleyDB is a little unusual - notice the directory that we 
change into before running configure.

Also notice that we are using a 3.x version of BerkeleyDB. The current release if 4.X
but SquidGuard needs the older version.

Now we can download and install SquidGuard:

> wget http://ftp.teledanmark.no/pub/www/proxy/squidGuard/squidGuard-1.2.0.tar.gz
> tar -xvzf squidGuard-1.2.0.tar.gz
> cd squidGuard-1.2.0
> ./configure --with-db=/usr/local/BerkeleyDB.3.2
> make
> make install
> mkdir /usr/local/squidGuard
> mkdir /usr/local/squidGuard/logs
> cp samples/sample.conf /usr/local/squidGuard

And now squidGuard is installed.

Now lets configure squid to utilize squidGuard. We'll need to edit the squid.conf
file at /usr/local/squid/squid.conf. Look for the line:

  #  TAG: redirect_program

Below this section add this line:

  redirect_program /usr/local/bin/squidGuard

And restart squid:

> service squid restart

Now squid will load and use squidGuard.

Next lets install the blacklists:

> cd /usr/local/squidGuard
> wget http://ftp.teledanmark.no/pub/www/proxy/squidGuard/contrib/blacklists.tar.gz
> tar -xvzf blacklists.tar.gz
> chmod --recursive g+w blacklists
> chown --recursive squid.squid blacklists

The next step is to configure squidGuard. We'll start with a very basic setup and
then expand it later using the webmin interface.

Create a new file at /usr/local/squidGuard/squidGuard.conf with the following
contents:

	logdir /usr/local/squidGuard/logs
	dbhome /usr/local/squidGuard/blacklists

	source localnet {
	        ip      172.0.0.0/8
	}

	source localhost {
	        ip      127.0.0.1
	}

	dest ads {
	        domainlist      ads/domains
	        urllist         ads/urls
	        #expressionlist  ads/expressions
	}

	dest audio-video {
	        domainlist      audio-video/domains
	        urllist         audio-video/urls
	        #expressionlist  audio-video/expressions
	}

	dest gambling {
	        domainlist      gambling/domains
	        urllist         gambling/urls
	        #expressionlist  gambling/expressions
	}

	dest mail {
	        domainlist      mail/domains
	        #urllist         mail/urls
	        #expressionlist  mail/expressions
	}

	dest proxy {
	        domainlist      proxy/domains
	        urllist         proxy/urls
	        #expressionlist  proxy/expressions
	}

	dest violence {
	        domainlist      violence/domains
	        urllist         violence/urls
	        expressionlist  violence/expressions
	}

	dest aggressive {
	        domainlist      aggressive/domains
	        urllist         aggressive/urls
	        #expressionlist  aggressive/expressions
	}

	dest drugs {
	        domainlist      drugs/domains
	        urllist         drugs/urls
	        #expressionlist  drugs/expressions
	}
	
	dest hacking {
	        domainlist      hacking/domains
	        urllist         hacking/urls
	        #expressionlist  hacking/expressions
	}
	
	dest porn {
	        domainlist      porn/domains
	        urllist         porn/urls
	        expressionlist  porn/expressions
	}
	
	dest warez {
	        domainlist      warez/domains
	        urllist         warez/urls
	        #expressionlist  warez/expressions
	}
	

	acl {
	        localnet {
	                pass !porn all
	                redirect http://www.acme.net
	        }
	
	        localhost {
	                pass !porn all
	                redirect http://www.acme.net
	        }
	
	        default {
	                pass !porn all
	                redirect http://www.acme.net
	        }
	}

Save the file. 

Next let's set permissions:

> cd /usr/local/squidGuard
> chown --recursive squid.squid *

Restart squid:

> service squid restart

Now squidGuard is running.

Next lets install webmin. Webmin can be downloaded from: 

	http://www.webmin.com

We'll use the RPM to simplify the install.

The install goes like this:

> wget http://unc.dl.sourceforge.net/sourceforge/webadmin/webmin-1.100-1.noarch.rpm
> rpm -U webmin-1.100-1.noarch.rpm

That's about it. Webmin is now installed on the server and can be accessed on 
port 10000. The default user is "root" and the password is the same as the 
root password.

Webmin includes a module for managing Squid by default so there is nothing to
add. We just need to configure the module to know where our install of Squid is located.

Follow these steps:

1. Login to Webmin
2. Click the Servers icon on the top menu bar.
3. Click the Squid Proxy Server icon.
4. Click the Module Config link under the top menu bar.
5. In the "System Configuration" section of the module config form set the following:

a. Full path to squid config file ==> /usr/local/squid/etc/squid.conf
b. Squid executable ==> /usr/local/squid/sbin/squid
c. Full path to PID file ==> /usr/local/squid/var/log/squid.pid
d. Full path to Squid cache directory ==> /usr/local/squid/var/cache
e. Squid cachemgr.cgi executable ==> /usr/local/squid/libexec/cachemgr.cgi
f. Full path to squid log directory ==> /usr/local/squid/var/logs

6. Click the save button at the bottom of the form.

That does it. Now Webmin can be used to manage Squid.

Next lets install a webmin module for managing SquidGuard.

1. Login to Webmin
2. Click the "Webmin" icon in the top menu bar.
3. Click the "Webmin Configuration" icon.
4. Click the "Webmin Modules" icon.
5. Complete the "Install Module" form as follows:

a. Select "From FTP or HTTP URL" and enter the url:

	http://www.niemueller.de/webmin/modules/squidguard/squidguard-0.91.2.wbm.gz

b. Select "Grant access only to users and groups" and enter "root".
c. Press the "Install Module From File" button.


Next to configure the module:

1. Login to Webmin
2. Click the "Servers" icon in the top menu bar.
3. Click the "SquidGuard" icon.
4. Click the "Module Config" link below the top menu bar.
5. Complete the form as follows:

a. Full path to Squidguard configuration file ==> /usr/local/squidGuard/squidGuard.conf
b. Full path to binary for SquidGuard ==> /usr/local/bin/squidGuard
c. Full path to PID file of Squid ==> /usr/local/squid/var/log/squid.pid
d. User the Squid runs as ==> squid
e. Group that Squid runs as ==> squid
f. Use database to extract user information ==> No 
g. Press the Save button.

And that takes care of the squidGuard module for Webmain.


July 2010
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Reliable Penguin offers Linux Server Migrations, Systems Administration & Programming. Visit our main website at:

http://www.reliablepenguin.com

Search

Bookmark and Share

XML Feeds

free blog tool