Squid Proxy Server

Sunday, June 14, 2009
Your Ad Here
Squid Proxy Server
Basic Configuration
The main configuration file for squid proxy server is /etc/squid/squid.conf.

The Squid Proxy Server has a dependency on a DNS Server. Please be noted,
while configuring the proxy client, what you only need to do is, specify the proxy
server’s address and the port number the proxy server is listen to in the browser
setting. There is no need to define the DNS or Router’s address in the TCP/IP
properties in the client machine.

So, please check the /etc/resolv.conf file whether you have already putted any
‘nameserver’ entry on not. The Squid Proxy Server listens to Port 3128 by default.
And by default it will reject all packets. If you want to allow users from your
network only to get the service from squid proxy server – modify the
/etc/squid/squid.conf file as follows. Here we are assuming our network address
is 192.168.0.0/24.

First of all find out the visible_hostname directive in the squid.conf file. By
default it sets to none. Just below the line # none – place an entry like this –

visible_hostname hostname or FQDN

Now find out ‘acl all’ directive in the file. You will find a line like the following –
acl all src 0.0.0.0/0.0.0.0

The above directive is a way to define every hosts in every network, src keyword
define the “source”, by “all” access control list name. If you move downwords,
you will find a line like this –
http_access deny all

Using the two lines, acl all src 0.0.0.0/0.0.0.0 and http_access deny all, the
squid proxy server disallow all the clients to access the proxy service. If you
replace deny with allow in http_access deny all line here, it will allow all clients
to access the serveice. However our task here is to allow our network only. So
put a line that will define you network with an acl name and allow it using the
http_access directive while keeping the default setting. You can write a directive
like this just after the acl all src 0.0.0.0/0.0.0.0 line –
acl ourlan src 192.168.0.0/255.255.255.0

Also put a line just before the http_access deny all directive like the following –
http_access allow ourlan

While allowing clients, Squid Proxy Server goes through the policy one after
another, top to bottom. If it finds any match related to the current packet, it
takes decision on that - whether the client will be allowed or denied.

To start/stop/restart the squid service you can execute the following command
respectively –

service squid start
service squid stop
service squid restart

chkconfig squid on command will start squid automatically at booting time.


User authenticated access to Squid Proxy

The user can be authenticated from the local system (the squid proxy server) through
ncsa authentication or from an LDAP server like Novell' s NDS or e-Directory or Microsoft's
Active Directory.

I am sending you the ncsa authentication implementation....

1. First of all, create a password file for the users and assign read permission to all.

touch /etc/squid/squid_passwd
chmod o+r /etc/squid/squid_passwd

2. Create Users and Passwords for the users -

htpasswd /etc/squid/squid_passwd user_1
htpasswd /etc/squid/squid_passwd user_2
htpasswd /etc/squid/squid_passwd user_n

3. Modify /etc/squid/squid.conf to support ncsa_auth program
Open the /etc/squid/squid.conf in vi editor, find out auth_param directives, and add the
following line just below the last auth_param directives -

auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squid_passwd

Move to acl section in the /etc/squid/squid.conf file - you can find out acl all directive
by pressing /acl all and press . Add the follwing line -

acl ncsa_users proxy_auth REQUIRED

Scroll down to http_access deny all directive and insert a line at the top as follows -

http_access allow ncsa_users

4. Restart your Squid proxy server -

service squid restart

Web site restriction through Squid Proxy

Open the /etc/squid/squid.conf in vi editor - move to acl ncsa_users proxy_auth
REQUIRED
add a line as follows -

acl blockdomain dstdomain "/etc/squid/blocked-domain-list"

Scroll down to http_access allow ncsa_users
put a line at the top like this -

http_access deny blockdomain

After modification, it will look like these -
...
http_access deny blockdomain
http_access allow ncsa_users
http_access deny all

Now create a file in /etc/squid, named blocked-domain-list

Define the name of th e web sites you want to block as follows -
.xxx.com
.yyy.com

Please be noted, you can only define one domain name in a single line.

Restart your Squid proxy server -

service squid restart

There are several methods of using a block list with squid. One of them is the Malware
Block list. Let us check how to use this list.

Now, it is time to check, the activities of squid proxy server. By default squid
generates log report in /var/log/squid directory. The access.log reports you
information about website access using your proxy server where cache.log and
store.log keep information about cached information. Commands are available
to pipe out information. However, there are so many utilities available in the
Internet to show you information in easily readable format.

In production environment I use SARG – the Squid Analysis Report Generator.
SARG helps you to analysis squid-log information using a browser where you can
categorize information. Top of that it is free.

First of all, download the software. I have downloaded it, sarg-2.2.2.tar.gz, from
http://sarg.sourceforge.net/sarg.php.

Go to the directory where you have downloaded the software and extract it using
the following command.
tar xzvf sarg-2.2.2.tar.gz

The command will extract the file in sarg-2.2.2 directory. Change your working
directory there – execute cd sarg-2.2.2
./configure –-enable-htmldir=/var/www/html/report
It is time to compile and install the software. Execute the following commands –
make && make install

By default the sarg binary directory is /usr/bin, where the sarg configuration file
is saved in /usr/local/sarg directory. The name of the configuration file is
sarg.conf.

Now you have to modify /usr/local/sarg/sarg.conf so that it will find the
access.log file, generated by squid, and generate a report by creating necessary
files in a directory.

In my case, I define minimum parameters like follows –
access_log /var/log/squid/access.log
output_dir /var/www/html/squid/squid-reports

You will find the access_log and output_dir parameters in sarg.conf file. Remove
the # and make necessary changes. In my case the squid directory is created in
/var/www/html directory. You do not need to create squid-report directory, rather
the sarg software will create it. You have to make it sure whether squid has
enough permission to create file there in /var/www/html/squid directory.

Now, generate the report that will be used by “sarg” using the following command

sarg –f /usr/local/sarg/sarg.conf

Now, configure Apache to access this report from your browser. What I usually do
is, I put the following Alias directives in my /etc/httpd/conf/httpd.conf file –

Alias /report “/var/www/html/squid/squid-reports/”

Options Indexes Includes


Restart your apache web server. From your web browser see the fascinating
report using – http://squid_server’s_ip_address/report

Here I am putting some screen shots –







Thing is that whenever you run sarg –f /usr/local/sarg/sarg.conf, sarg-report
will be created. We can submit a cron job, so that the system will execute it
automatically. In my network, I put the following line after executing crontab –e,

0 * * * * /usr/bin/sarg –f /usr/local/sarg/sarg.conf


Setting customized message

Create an html file with customized message and save it to /etc/squid/error
directory.

Now put the following directives in /etc/squid/httpd.conf –

acl blacklist dstdomain “/var/lib/squidguard/BL/blacklist”
http_access deny blacklist
deny_info blocked.htm blacklist

Restart squid proxy server and try to access any restricted site, as per
/var/lib/squidguard/BL/blacklist, from your workstation.

See the result in my case –

Labels: , , , , , , , , , ,

 
posted by Gautam at 9:08 PM, | 0 comments

DUMP and RESTORE

Monday, May 4, 2009
Your Ad Here
DUMP and RESTORE:
Dump and Restore is used to take backup or restore ‘only ext2 or ext3’ file system. This
particular dump and restore utility can be u sed to take full or incremental backup.
To take a full backup of the /home filesystem onto the tape device nst1 we can use the
following command –
dump -0u-f /dev/nst0 /home
Here we specify 0 to define full backup and u (dump -0u-f /dev/nst0 /home)
is specified so that dump information will be recorded for future use of dump. Generally
administrators love to take full backup on weekly or monthly basis while regularly take
incremental backup. For incremental backup, the command may be as follows –
dump -4u-f /dev/nst0 /home
Please note, we use 4 instead of 0 to define incremental backup.
To restore data backed up with dump command we use restore command. For example,
suppose we had /dev/hda9 mounted on /home. On a clean device mounted on /home,
first of all we should change the working directory there and then use the following
command – restore –rf /dev/nst0
Whenever we use dump command using –u option, it will update /etc/dumpdates, which
actually contents the dump-information.

SOME BACKUP RELATED COMMANDS:

To Erase Dat Drive
mt –f /dev/st0 erase
To rewind the Dat Drive
mt –f /dev/st0 rewind
To backup the www Server
find /etc/httpd/conf /usr/local –print | cpio –ovcB > /dev/st0
To backup up Sendmail Mail Server
find /var /home /etc/mail –print | cpio –ovcB > /dev/st0

Labels: , , , , , , , , , ,

 
posted by Gautam at 4:41 AM, | 0 comments

IP Forwarding

Saturday, April 25, 2009
Your Ad Here
IP Forwarding is a feature of the LINUX kernel, which can be turned on or off,
if needed, without rebooting the computer. It is very much needed, especially
when a LINUX system is used as a Firewall/Router or a Proxy Server for
a network and is doing Network Address Translation (NAT) to masquerade
a private subnet behind a single public IP address. In this regard,
what Administrators do is –
Install two network cards (one will be assigned with the real or public IP
address and the second will be assign ed with the private IP address.)
To turn IP Forwarding on we can run the following command –
echo 1 > /proc/sys/net/ipv4/ip_forward
The above command will enable IP forwarding for the current session,
as the default setting is “disable”. To make it permanent, modify /etc/sysctl.conf as follows -
net.ipv4.ip_forward = 1
By default the value 0 is set, means the NATing is disabled. However, after modifying
/etc/sysctl.conf, reboot your machine to make it permanent. During the time of
booting the computer will check the /etc/sysctl.conf and read the IP forwarding related
parameters net.ipv4.ip_forward = x and load it to /proc/sys/net/ipv4/ip_forward file.
However, by executing - echo 1 > /proc/sys/net/ipv4/ip_forward you can enable IP
forwarding instantly.

Labels: , , , , , ,

 
posted by Gautam at 1:10 AM, | 0 comments