The Perfect SpamSnake - Ubuntu Jaunty Jackalope

Author: Mohammed Alli

Postfix w/Bayesian Filtering and Anti-Backscatter (Relay Recipients), Apache, Mysql, Dnsmasq, MailScanner (Spamassassin, ClamAV, Pyzor, Razor, DCC-Client), MailWatch, SPF Checks, FuzzyOcr, PDF/XLS/Phishing Sanesecurity Signatures, Postfix-GLD (Greylisting Optional), Logwatch Statistical Reporting (Optional), Outgoing Disclaimer with alterMIME (Optional), FireHOL (Iptables Firewall)

Version 2.5

This tutorial shows how to set up an Ubuntu Jaunty Jackalope based server as a spamfilter in Gateway mode. In the end, you will have a SpamSnake Gateway which will relay clean emails to your MTA. You will also be able to view your incoming queue, train your SpamSnake and carry out a few more advanced operations via MailWatch.

I cannot offer any guarantees that this will work for you, the same way it's working for me.

I will use the following software:

  • Web Server: Apache 2 with PHP 5
  • Database Server: MySQL 5.0
  • Mail Server: Postfix
  • Caching DNS Server: Dnsmasq
  • MailScanner: MailScanner v4.76
  • MailWatch: MailWatch v1.0.4

Credit goes to the guys at HowtoForge and the developers of MailScanner, MailWatch, ClamAV, Apache, Mysql and Postfix.


Install the base system using the minimal option.

1. Get root Privileges

Enable the root login by running the following and giving root a password. You can then directly log in as root:

sudo passwd root


 2. Install vim-nox (Optional)

I'll use vi as my text editor in this tutorial. The default vi program has some strange behaviour on Ubuntu and Debian; to fix this, we install vim-nox:

aptitude install vim-nox

(You don't have to do this if you use a different text editor such as joe or nano.)


 3. Configure The Network

Because the Ubuntu installer has configured our system to get its network settings via DHCP, we have to change that now because a server should have a static IP address. Edit /etc/network/interfaces and adjust it to your needs (in this example setup I will use the IP address

vi /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static

Then restart your network:

/etc/init.d/networking restart

Then edit /etc/hosts. Make it look like this:       localhost.localdomain   localhost     server1

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Now run:

echo > /etc/hostname
/etc/init.d/ start

Afterwards, run:

hostname -f

Both should show now.


4. Update your Linux Installation

Edit /etc/apt/sources.list. Comment out or remove the installation CD from the file and make sure that the universe and multiverse repositories are enabled. It should look like this:

# deb cdrom:[Ubuntu-Server 9.04 _Jaunty Jackalope_ - Release amd64 (20090421.1)]/ jaunty main restricted

#deb cdrom:[Ubuntu-Server 9.04 _Jaunty Jackalope_ - Release amd64 (20090421.1)]/ jaunty main restricted
# See for how to upgrade to
# newer versions of the distribution.

deb jaunty main restricted
deb-src jaunty main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb jaunty-updates main restricted
deb-src jaunty-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb jaunty universe
deb-src jaunty universe
deb jaunty-updates universe
deb-src jaunty-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb jaunty multiverse
deb-src jaunty multiverse
deb jaunty-updates multiverse
deb-src jaunty-updates multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb jaunty-backports main restricted universe multiverse
# deb-src jaunty-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb jaunty partner
# deb-src jaunty partner

deb jaunty-security main restricted
deb-src jaunty-security main restricted
deb jaunty-security universe
deb-src jaunty-security universe
deb jaunty-security multiverse
deb-src jaunty-security multiverse

Then run the following to update the apt package database:

aptitude update

Run the following to install the latest updates:

aptitude safe-upgrade

If you see that a new kernel gets installed as part of the updates, you should reboot the system afterwards:


5. Change The Default Shell

/bin/sh is a symlink to /bin/dash, however we need /bin/bash, not /bin/dash. Therefore we do this:

dpkg-reconfigure dash

Install dash as /bin/sh? <-- No


6. Disable AppArmor

AppArmor is a security extension (similar to SELinux) that should provide extended security. In my opinion you don't need it to configure a secure system, and it usually causes more problems than advantages (think of it after you have done a week of trouble-shooting because some service wasn't working as expected, and then you find out that everything was ok, only AppArmor was causing the problem). Therefore I disable it (this is a must if you want to install ISPConfig later on).

We can disable it like this:

/etc/init.d/apparmor stop
update-rc.d -f apparmor remove
aptitude remove apparmor apparmor-utils


7. Install Some Software

Now we install a few packages that are needed later on:

aptitude install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl libdb4.6-dev libpcre3 libpopt-dev lynx m4 make ncftp nmap openssl perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++ build-essential unrar


8. Synchronize the System Clock

It is a good idea to synchronize the system clock with an NTP (network time protocol) server over the internet. Simply run :

apt-get install ntp ntpdate


9. Caching Dnsmasq

apt-get install dnsmasq

Edit /etc/dnsmasq.conf and make Dnsmasq listen on localhost:


Edit /etc/resolv.conf and add the following to the top of the list:

Share this page:

32 Comment(s)

Add comment


From: at: 2009-06-22 15:13:39

These are live notes that I collected as I got this great Spam Snake working: (and do note that it works very well - when you overcome a 'few' problems)

The line with: [apt-get install mailscanner razor pyzor clamav-module] produces a problem finding the clamav-module: (missing resolution steps outlined)

Steps to get and install the [Spam Snake] clamav-module:

Be sure you have perl installed... (if not sure use: aptitude install perl) then enter:

perl -MCPAN -e shell

If you are prompted if you want to configure perl automatically choose: yes

When you are at [cpan] prompt enter (steps 1-7):

1) install CPAN (gets any upgrades for perl / cpan)
2) reload cpan (reload any new version)
3) test File::Scan::ClamAV (it will download the ClamAV module)
4) look File::Scan::ClamAV (shell to the ClamAV area)
5) make install (will perform the ClamAV-module install)
6) exit
7) quit

All done, now we have the ClamAV-Module!

UPDATE: You will likely find that continuing with the [SpamSnake] setup that there will be other missing PERL modules:

I outline the steps to resolve this (it was pure research) - and it now works:

Type: (at Linux command line)

cpan -i ExtUtils::Command::MM
aptitude install libconvert-binhex-perl
cpan -i Checker::ISA
cpan -i Archive::Zip
aptitude install libyaml-perl
cpan -i OLE::Storage_Lite

Now we are almost there: - see if it now works OK

Test the final perl setup with this:


The given steps (in this Spam Snake guide) shown as:

Create /etc/postfix/relay_recipients and add the following: OK OK

Create /etc/postfix/transport and add the following: smtp:[192.168.0.x] smtp:[192.168.0.x]

Create /etc/postfix/relay_domains and add the following: OK OK

Must NOT include any reference to any declared virtual email domains, or you will see this error:

"postfix/trivial-rewrite: warning: do not list domain in BOTH virtual_mailbox_domains and relay_domains"

The line that has: smtp:[192.168.0.x] must be a full and valid IP address!

I have performed several email tests and I am very happy with the final process, Additionally, all outgoing emails show this text report:

This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Peter Bowey

From: at: 2009-12-11 05:36:56

In the Ubuntu / Debain's /etc/init.d/mailscanner startup script (or the default MailWasher /etc/rc2.d/S20mailscanner) to include the required UID / GUID on the daemon start line: (see next line)

Find the line in the Ubuntu /etc/init.d/mailscanner distro (or the orig MailScanners own .tar distro = /etc/rc2.d/S20mailscanner) that has:

start-stop-daemon --start --quiet --nicelevel $run_nice --exec $DAEMON --name $NAME -- $DAEMON_ARGS \

and change it to:

start-stop-daemon --start --quiet --nicelevel $run_nice --chuid postfix --exec $DAEMON --name $NAME -- $DAEMON_ARGS \

 This doesn't work for me since I run Karmic. I get an error that Mailscanner can't set the gid in ... line ...


start-stop-daemon --start --quiet --nicelevel $run_nice --chuid postfix:www-data --exec $DAEMON --name $NAME -- $DAEMON_ARGS \

Runs like a charm now with no errors.


From: at: 2009-06-23 04:02:04

You see an error like this: (mail.log)

"ClamAV-autoupdate: ClamAV updater /usr/local/bin/freshclam cannot be run"

Solution: create a symbolic link from:   /usr/bin/freshclam -> /usr/local/bin/freshclam

Now the path reference works:

The [mail.log] will now show something like this:

"update.virus.scanners: Running autoupdate for clamav"
"ClamAV-autoupdate[31509]: ClamAV did not need updating"

Peter Bowey

From: at: 2009-06-25 13:19:42

After moving the newly installed MailScanner to /opt and renaming the repository installed version to /etc/MailScanner.dist  this leaves the MailScanner init script still configured to look for Mailscanner.conf in /etc/MailScanner. Either changing the init script or creating a link fixes this.

From: at: 2009-06-26 16:25:59

I was one of the likely many that recently updated Ubuntu/Debian PERL to the latest release of 5.10:

I found this latest PERL killed MailScanner - with logged (mail.log) reports of: "Insecure dependency in chown while running with the -T switch in ..../MailScanner/ on line xxxx". MailScanner would then 'abort' any exec calls or just hang - leaving no outward flow of emails! Yet, after hours of research - there is a solution (other than going back to the older PERL V5.9.x)!

This new 'problem' results from the new PERL Taint Mode enforcement policy! This new 'rule' enables (and enforces) a number of wise security checks with programs (exec) called with different user and / or group ids.

There is a solution, and I have tested it with the latest release .tar of MailScanner v4.78.1:

In the Ubuntu / Debain's /etc/init.d/mailscanner startup script (or the default MailWasher /etc/rc2.d/S20mailscanner) to include the required UID / GUID on the daemon start line: (see next line)

Find the line in the Ubuntu /etc/init.d/mailscanner distro (or the orig MailScanners own .tar distro = /etc/rc2.d/S20mailscanner) that has:

start-stop-daemon --start --quiet --nicelevel $run_nice --exec $DAEMON --name $NAME -- $DAEMON_ARGS \

and change it to:

start-stop-daemon --start --quiet --nicelevel $run_nice --chuid postfix --exec $DAEMON --name $NAME -- $DAEMON_ARGS \

The effect of this change allows mailscanner to run with the required UID to prevent the new PERL enforced 'taint mode'. Please note that this means that MailWasher must have the UID set to postfix in the MailScanner.conf file.

Another change I found that was essential was to add the clamav user to the postfix group. Without this change I got permission denied errors when the clamd (daemon) was called by MailWasher to check emails on the /var/spool/postfix/incoming folder. (with UID = postfix).

With the new changes I have no further faults or errors using MailScanner (with all the extra 'SpamSnake' additions). This new code runs live on my own dedicated business mail server - so it is a live and real test! Normally, I used to recieve about 350 spam emails per day, now it has dropped to 2-3 that 'leak' through the 'SpamSnake'.

If any one is interested, I have ported the latest MailScanner tar release v4.78.1 to a true debain / ubuntu style package - without the generic /OPT/.... directory.

Peter Bowey

From: Frank Holler at: 2009-10-12 10:33:20


I am running Debian and mta exim4 and my error was different: "Insecure dependency in exec while running with -T switch at /usr/share/MailScanner//MailScanner/ line 374"

So i changed  /etc/init.d/mailscanner and added "--chuid=Debian-exim" and the error disappeared. This helped.

Thanks alot.

From: Nivethan at: 2010-02-15 10:00:48

Thank you verymuch, your method worked! I had been wondering with the mail scanner looping problem for two days and just before was going to go change back to a older perl version fortunately I found your comment! wow! brilliant....

From: Jamie Strandboge at: 2009-12-28 15:49:00

I noticed that this tutorial recommends to disable all of AppArmor. Unless you have a very specific need to do so, this is not recommended. The apparmor profiles shipped in Ubuntu are designed to work with the default installation. If a particular profile is causing you trouble, please disable the profile or put it in complain mode, and leave the other profiles that are not causing problems to do their jobs. Better yet, file a bug. :) See my blog entry at for details.

From: at: 2009-06-28 03:30:11

Update for Ubuntu / Debian:

The default debian system does not have a /var/lock/susbsys, and in a normal chroot - it needs to be created before the MailWasher Daemon starts:

I have amended the required change => /etc/rc2.d/S20mailscanner

16.2 Fix to Disable Permission Checks on MailScanner Directories

Edit /etc/rc2.d/S20mailscanner to look like:

check_dir /var/spool/MailScanner       ${user:-postfix} ${group:-postfix}
check_dir /var/lib/MailScanner         ${user:-postfix} ${group:-postfix}
check_dir /var/run/MailScanner         ${user:-postfix} ${group:-postfix}
check_dir /var/lock/subsys             ${user:-root}    ${group:-root}
check_dir /var/lock/subsys/MailScanner ${user:-postfix} ${group:-postfix}
In the file /etc/default/mailscanner, make sure this parameter is at 1:
The logic of the above is made apparent when you see the rest of the /etc/rc2.d/S20mailscanner file contents:

    if [ ! -d $1 ]; then
        mkdir -p "$1" || \
            fail "directory $1: does not exist and cannot be created"
    actual="$(stat -c %U $1)"
    if [ "$actual" != "$2" ]; then
        chown -R "$2" "$1" || \
            fail "directory $1: wrong owner (expected $2 but is $actual)"
    actual="$(stat -c %G $1)"
    if [ "$actual" != "$3" ]; then
        chgrp -R "$3" "$1" || \
            fail "directory $1: wrong group (expected $3 but is $actual)"
user=$(echo $(awk -F= '/^Run As User/ {print $2; exit}' $CONFFILE))
group=$(echo $(awk -F= '/^Run As Group/ {print $2; exit}' $CONFFILE))
check_dir /var/spool/MailScanner       ${user:-postfix} ${group:-postfix}
check_dir /var/lib/MailScanner         ${user:-postfix} ${group:-postfix}
check_dir /var/run/MailScanner         ${user:-postfix} ${group:-postfix}
check_dir /var/lock/subsys             ${user:-root}    ${group:-root}  ## required to CREATE folder!
check_dir /var/lock/subsys/MailScanner ${user:-postfix} ${group:-postfix}

The above change avoids the need to dynamically add these directories through the slower use of /etc/rc.local (as I have seen Ubuntu / Debian MailScanner use as a 'solution' when they discovered that the MailScanner ( /var/xxx folders ) were lost after a reboot.

A lot of debian / ubuntu users use enhanced protection to the /var/xxx folder areas, and then it is normal to have to create 'real' chroot access across reboots.”

Spamsnake's author mentions the need to install clamav-module; this is an older perl module that is superseded by Ubuntu's clamav-daemon. The author is actually using this new daemon for mailwasher - evident by the
MailWasher.conf file with:

Virus Scanners = clamd                     ## clamav daemon use

So it not required to chase the older perl clamav-module; just get the latest Ubuntu clamav-daemon

aptitude install clamav-daemon

Notes: The clamav-daemon is faster than the previous perl
clamav-module! MailSanners own wiki states this change and recommended use.

Peter Bowey

From: Anonymous at: 2009-09-02 22:32:43

I got this error after I do postmap /etc/postfix virtual:

postmap: fatal: /etc/postfix/, line 43: missing '=' after attribute name:  "postconf -e alias_maps = hash:etc/aliases"


From: Anonymous at: 2009-07-31 03:50:25


Just letting you know that DCC has been removed from all the debian apt sources.

There was a security bug which was causing issues to the dcc wich are unfixable



From: Anonymous at: 2010-08-05 18:47:55

This bug was fixed in dcc 1.3.51 - whereas this article describes installing 1.3.103.

 So... not an issue.

From: Anonymous at: 2009-08-03 02:04:36


The latest version of mailscanner is only compatable with mailtools 1.77

Which I couldnt find in apt, I had to install it manually following this

From: at: 2009-08-10 16:29:57

Before step 16.4 where you start MailScanner, you will need to set the permissions on the spool folders like this:

chown -R postfix:www-data MailScanner/

From: at: 2009-08-10 16:22:44

At step 13, it is mentioned that we need to install Python 2.5, but never specifically in the code blocks. In case anyone gets stuck, don't forget to run this before you do step 13:

apt-get install python2.5

From: citybird at: 2009-10-23 13:11:37

 the following setting should also be changed in conf.php in step 17.5

define(MS_CONFIG_DIR, '/opt/MailScanner/etc/');

From: bearman at: 2009-09-25 06:27:32

We got it!

It works if Y substitute:






From: nibb13 at: 2009-09-11 18:28:18

Try changing line 4 of create.sql to read:

-- -------------------------------------

That seems to have done the trick for me.

Cheers, nibb13

From: at: 2010-02-18 02:28:24

This is one of the most interesting and useful "how tos", but extremely unprofessionally done and has lots of bugs. I say thank you to the author, but please read the comments and edit the steps and missteps. 

 Also, some steps are extremely for kids who don't know computers, but some steps you say that require extra research that expert users in computers, but not in linux won't be able to follow.

 Also to make it easier, when you say "edit this file" you can simpler provide a command "vi/nano /etc/blahblahblah"

 Now, step 17.9, a little lower you say "Edit the SpamAssassin v310.pre to enable Razor and DCC"
where is it? where do I find it to edit?

From: Jim Morbid at: 2010-03-31 13:17:23

joe /etc/mail/spamassassin/v310.pre



From: ScarEye at: 2009-09-06 02:49:04

17.2 is kicking my ass this what I get when I run

mysql -p < create.sql

root@smtpgw:/usr/src/mailwatch-1.0.4# mysql -p < create.sql
Enter password:
ERROR 1064 (42000) at line 4: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-------------------------------------------------------



CREATE DATABASE /*' at line 1

Here is a few lines of create.sql

-- MySQL dump 8.23
-- Host: localhost    Database: mailscanner
-- Server version       3.23.58

-- Current Database: mailscanner

CREATE DATABASE /*!32312 IF NOT EXISTS*/ mailscanner;

USE mailscanner;

-- Table structure for table `audit_log`

CREATE TABLE audit_log (
  timestamp timestamp(14) NOT NULL,
  user varchar(20) NOT NULL default '',
  ip_address varchar(15) NOT NULL default '',
  action text NOT NULL

-- Table structure for table `blacklist`

CREATE TABLE blacklist (
  id int(11) NOT NULL auto_increment,
  to_address text,
  to_domain text,
  from_address text,
  PRIMARY KEY  (id),
  UNIQUE KEY blacklist_uniq (to_address(100),from_address(100))

-- Table structure for table `geoip_country`

CREATE TABLE geoip_country (
  begin_ip varchar(15) default NULL,
  end_ip varchar(15) default NULL,
  begin_num bigint(20) default NULL,
  end_num bigint(20) default NULL,
  iso_country_code char(2) default NULL,
  country text,
  KEY geoip_country_begin (begin_num),
  KEY geoip_country_end (end_num)



I ran a few lines manually and they seem to work.  Then I tried to re-run mysql -p < create.sql

but no luck.

Please help, so close to being done.




From: at: 2014-04-01 11:42:49


 To fix the error 1064 with this setup on a new system, just remove the (14) on the timestamp timestamp entries in create.sql

 There are 2 one at the top and one on line 78 (to get there in nano press CTRL _)

From: ScarEye at: 2010-01-12 15:02:55

Anyone here know how to fix the 2010 bug with spamassassin?  I see this here.  Check this out.

 But in spamsnake we disbale, so what's the work around?




From: Anonymous at: 2010-08-05 18:55:41

In step 17.10, I ran into an error when trying to run:

 mysql -u sa_user -p sa_bayes < /path/to/bayes_mysql.sql

A simple fix is to add the following to the top of the .sql file:

 CONNECT sa_bayes;


From: shawn at: 2009-06-11 18:03:41

can this spam snake be configured to scan and relay to multiple mail hosts ?

From: randomxs at: 2009-06-14 04:45:29

There's no reason why it can't. I do it at work for multiple domains and mail servers.

From: Martin H at: 2009-07-15 20:06:12

And which changes you did to postfix configuration in order to make it work with multiple domains / mail servers??



From: Matt at: 2009-07-20 21:25:05

Add the domains to relay_domains, relay_recipients, and transport.

From: Anonymous at: 2009-06-13 07:33:08

I stopped reading at 8.:

 1. Statistically, brute force attack now has 100% bigger chances on guessing 'administrator' password. It's easier to guess one of two, than only one.

2. ubuntu server comes with vim installed by default. vim-nox is added support for perl, python and ruby.

5. why would you change default shell? If the scripts are broken, fix them; don't avoid the problem.

6. Now, that's a stupid thing to do. Again, as with 5, why not rather fix the problem, instead of avoiding it?

8. ntpdate is installed by default, and you don't need it if you have ntp service running. Hell, you can't even use ntpdate while ntpd is running.

From: Anonymous at: 2010-01-26 04:01:00

To run ntpdate while ntp is running simply use the -u switch.

From: maxsec at: 2009-06-14 19:29:12

you might want to to put in extra SA rules and also turn off many of the RBL's in SA.

 Also watch out for the spamlist settings in MailScanner.conf - usually better to do  this in SA rather than MS. The Spamhaus lists (Zen etc) can also block you if you are querying then alot - see their TOS on this.


Might be worth pointing at the performance and "Getting the most out of spamassassin" sections of the MailScanner Wiki



From: Sebastian at: 2009-12-20 15:10:54

Hi guys,

 you'd better issue

sa-learn --sync -D -p /opt/MailScanner/etc/spam.assassin.prefs.conf

 before doing

spamassassin -x -D -p /opt/MailScanner/etc/spam.assassin.prefs.conf --lint

This way you are initializing the database and after that the testout will succeed.


Best regards,