Sunday, January 5, 2014

How to install and configure Amavis, Clamav and Spamassassin on Debian Squeeze

Concept:

In this tutorial we will show you how to install and configure Amavis-new, clamAV and Spamassassin. We also integrate these packages with Postfix for better understanding that how they works with smtpd.

Amavis-new is a wrapper that can call any number of content filtering programs for spam detection, antivirus, etc. ClamAv is world famous opensource package for content filtering and Spamassassin is for spam protection.


First of all Update Debian Squeeze Souce List (Otherwise you can't install the optional packages):


===============================================================
deb ftp://ftp.se.debian.org/debian squeeze main
deb ftp://ftp.se.debian.org/debian squeeze main contrib non-free


deb http://http.us.debian.org/debian/ squeeze main contrib non-free
deb-src http://http.us.debian.org/debian/ squeeze main contrib non-free
===============================================================


Don't forget to update & upgrade:

    # apt-get update
    # apt-get upgrade

Installation on Debian squeeze:


    # apt-get install amavisd-new spamassassin clamav-daemon


Optional packages for better spam detection:


    # apt-get install libnet-dns-perl libmail-spf-query-perl pyzor razor libmail-spf-perl


Packages to enable scanning of attached archive files:
   
        # apt-get install arj bzip2 cabextract cpio file gzip lha nomarch pax rar unrar unzip unzoo zip zoo p7zip


Configuration [Clamav]:

The default behaviour of Clamav will fit our needs. A daemon is launched (clamd) and signatures are fetched every day.

For more Clamav configuration options, check the configuration files in /etc/clamav.

Add clamav user to the amavis group and vice versa in order for Clamav to have access to scan files:

    # adduser clamav amavis
    # adduser amavis clamav


Configuration [Spamassassin]:

Spamasssassin autodetects optional components and will use them if they are present. This means that there is no need to configure dcc-client, pyzor and razor.

Edit /etc/default/spamassassin to activate the Spamassassin daemon change ENABLED=0 to:

ENABLED=1

and to enable automatic rule updates change CRON=0 at the bottom to:

CRON=1


Now start Spamassassin: (not restart)

    # /etc/init.d/spamassassin start

Configuration [Amavis]:


First, activate spam and antivirus detection in Amavis by editing /etc/amavis/conf.d/15-content_filter_mode:

=====================================================================
use strict;

# You can modify this file to re-enable SPAM checking through spamassassin
# and to re-enable antivirus checking.

#
# Default antivirus checking mode
# Uncomment the two lines below to enable it
#

@bypass_virus_checks_maps = (
   \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);


#
# Default SPAM checking mode
# Uncomment the two lines below to enable it
#

@bypass_spam_checks_maps = (
   \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);

1;  # insure a defined return
======================================================================

After configuration Amavis needs to be restarted:

    # /etc/init.d/amavis restart


Postfix integration:

For postfix integration, you need to add the content_filter configuration variable to the Postfix
configuration file /etc/postfix/main.cf.. This instructs postfix to pass messages to amavis at a given IP address and port:

    content_filter = smtp-amavis:[127.0.0.1]:10024

Alternatively you can use the following command to do the same:
    # postconf -e "content_filter = smtp-amavis:[127.0.0.1]:10024


Next edit /etc/postfix/master.cf and add the following to the end of the file:


=====================================================================
smtp-amavis     unix    -       -       -       -       2       smtp
        -o smtp_data_done_timeout=1200
        -o smtp_send_xforward_command=yes
        -o disable_dns_lookups=yes
        -o max_use=20

127.0.0.1:10025 inet    n       -       -       -       -       smtpd
        -o content_filter=
        -o local_recipient_maps=
        -o relay_recipient_maps=
        -o smtpd_restriction_classes=
        -o smtpd_delay_reject=no
        -o smtpd_client_restrictions=permit_mynetworks,reject
        -o smtpd_helo_restrictions=
        -o smtpd_sender_restrictions=
        -o smtpd_recipient_restrictions=permit_mynetworks,reject
        -o smtpd_data_restrictions=reject_unauth_pipelining
        -o smtpd_end_of_data_restrictions=
        -o mynetworks=127.0.0.0/8
        -o smtpd_error_sleep_time=0
        -o smtpd_soft_error_limit=1001
        -o smtpd_hard_error_limit=1000
        -o smtpd_client_connection_count_limit=0
        -o smtpd_client_connection_rate_limit=0
        -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks

Also add the following two lines immediately below the "pickup" transport service:
[This will prevent messages that are generated to report on spam from being classified as spam.]

         -o content_filter=
         -o receive_override_options=no_header_body_checks
======================================================================


Reload postfix:

    # /etc/init.d/postfix reload

=======================================================================
Now content filtering with spam and virus detection is enabled. Yy@aHh0o0o...Great Job MAN..Done...
=======================================================================

2 comments: