[Edit 05.11.04 - Added information about validating users on Exchange]
[Edit 04.27.05 - Added information about needing to emerge spamassassin]
[Edit 04.29.05 - Added information about DNS servers]
Step By Step:
1. Install Gentoo
2. Emerge postfix, amavisd-new
3. Configure Postfix
4. Configure Amavisd-new
5. Configure SpamAssassin
To begin, I'm going to assume you have Gentoo up & running on a box. I have been using gentoo-sources with no problems on my spam filter, but I'm sure if you used a different kernel you could squeeze more performance out of it.
For reference, here's the machine I set this all up on:
Code: Select all
Single Processor
Intel Pentium III 450MHz(Katmai)
128MB RAM
RAID 1 on SCSI 8GB Drives
USE_FLAGS = "-X"I'm currently doing spam filtering for 3,700 Exchange mailboxes, and catching between 500 - 1000 spam messages per day. And to be honest, the machine listed above doesn't even break a sweat.
IMPORTANT: If possible, have your DNS servers for the machine on a local network! Using a DNS server a few hops away can considerably slow mail processing. Even using your ISP's DNS can cause major slowdowns and queue backups.
Ok, once your Gentoo box is booting up, emerge the following:
Code: Select all
emerge postfix
emerge amavisd-newCode: Select all
emerge spamassassinPostfix Configuration
Now you need to configure Postfix to work as a relay to the Exchange server only. You don't want mail being sent from this box. I'm taking the following information directly from Scott Henderson's excellent HOWTO ( http://www.geocities.com/scottlhenderso ... ilter.html ) Please note that I am not running postfix chroot, although you could & Scott gives instructions on doing this. Scott also covers a lot of other things, like sending root mail to another mailbox, improving logging performance, etc. so I recommend you read through his site. I'm just going to cover the basics here.
Edit the file /etc/postfix/master.cf and add this at the bottom
Code: Select all
smtp-amavis unix - - y - 2 smtp
-o smtp_data_done_timeout=1200
-o disable_dns_lookups=yes
127.0.0.1:10025 inet n - y - - smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yesThis sets up postfix to forward mail to this machine on port 10025, the port Amavisd listens on.
Next, edit the file /etc/postfix/main.cf and add the following at the bottom. Note that I've replaced my specific info with a filler.
Code: Select all
myorigin = my.network.com
myhostname = spamfilter.my.network.com
mydestination = my.network.com
mynetworks = x.x.x.x/y
biff = no
smtpd_banner = SMTPD_BANNER_HERE
message_size_limit = 25000000
local_transport = no local mail delivery
local_recipient_maps =
transport_maps = hash:/etc/postfix/transport
smtpd_helo_required = yes
#smtpd_helo_restrictions = reject_non_fqdn_sender, reject_unknown_sender_domain
#smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, reject_non_fqdn_recipient
content_filter = smtp-amavis:[localhost]:10024Of interest are the following lines
Code: Select all
smtpd_helo_required = yes
#smtpd_helo_restrictions = reject_non_fqdn_sender, reject_unknown_sender_domain
#smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, reject_non_fqdn_recipient
content_filter = smtp-amavis:[localhost]:10024Secondly, you may want to add these lines:
Code: Select all
header_checks = pcre:/etc/postfix/pcre-header.cf
body_checks = pcre:/etc/postfix/pcre-body.cfIMPORTANT If you add these lines, you need to at least have files (even blank) in the /etc/postfix dir. If anyone wants, send me a PM & I'll send you my copies of the files. I have built up quite a bit of stuff in them.
Next, you may want to edit the file /etc/postfix/access. Here you can put ip ranges, senders and domains to be rejected or accepted by postfix. Personally, I do not use this file, I just use the pcre-header & body files. If you do edit the access file, you need to run
Code: Select all
postmap /etc/postfix/accessOk, that should be the end of configuring postfix. You can start the postfix service now & check it by telneting into localhost on port 25. Got a response? So far, so good.
If you do change any postfix configuration files, esp. if you decide to use the pcre-header & body approach like I do, when you are done editing, just run
Code: Select all
postfix reloadConfiguring Amavisd-new
Ok, now amavisd-new is kinda like this glue that holds together all these different mail processing programs. Its a pretty neat idea, and once you understand that amavisd-new just coordinates these programs, its easy to work with. A stock install of amavisd-new gives clamd. You will need to emerge SpamAssassin yourself. Clamd will handle anti-virus scanning, and SpamAssassin will handle the spam filtering.
First, edit /etc/amavisd.conf & make the following changes
Code: Select all
Locate $mydomain = 'example.com' and change to your domain
Check that $daemon_user and $daemon_group are set to 'amavis' (done by the Gentoo ebuild I believe)
DO NOT remove the # from @bypass_virus_checks_acl!! You want to do virus scanning!
Remove the # from in front of $warnspamsender = 1;
Change $mailfrom_notify_ lines to point to "your.admin.mailbox\@your.domain.com";
Locate $spam_quarantine_to = 'spam-quarantine'; and add a # to the beginning. Go down one line & REMOVE the # from $spam_quarantine_to = "your.admin.mailbox\@your.domain.com";Many of the settings for SpamAssassin are taken from amavisd.conf! So, you can edit the SpamAssassin conf file all you want, but the changes won't work... so, here's what you have to set in amavisd-new
Code: Select all
Find the section # SpamAssassin settings
Notice the lines $sa_tag_level_deflt, $sa_tag2_level_deflt, $sa_kill_level_deflt. These are where you set the scores that SpamAssassin gives to a mail to mark it as spam. I have mine set to:
$sa_tag_level_deflt = 0.0;
$sa_tag2_level_deflt = 5.0;
$sa_kill_level_deflt = $sa_tag2_level_deflt;
so, a score of 5 marks it as spam & kills the mail.Virus Scanning
To be honest, this works out of the box. Clamd sets up a cron job to check for updates daily, and I've never had a problem. Clamd logs to /var/log. Great app & it catches a TON of viruses for us.
SpamAssassin Setup
As I mentioned above, the most important setting for SpamAssassin, the scoring of mails, is controlled through /etc/amavisd.conf. All other configuration for SpamAssassin is done in /etc/mail/spamassassin/local.cf Here's a few settings you can play with
Code: Select all
bayes_auto_learn 1
bayes_auto_learn_threshold_nonspam 1
bayes_auto_learn_threshold_spam 14.00Also, local.cf is used to put SpamAssassin rules into. I have many rules that I use. PM me & I'll send them to you.
Final Setup
You should now be ready to start filtering mail! You need to add some programs to your default runlevel
Code: Select all
rc-update add postfix default
rc-update add amavisd default
rc-update add clamd defaultFinal Thoughts
There is lots and lots of additional stuff you can do. You can play around with the headers that are added to the emails, you can quarantene differently, set up different notifications, and on & on. The amavisd.conf file is very well commented, so read through it.
Notice that I didn't touch the Exchange server at all. If you wanted to get advanced, you could do LDAP lookups to verify that the recipient exists. This would be overkill in my case, and probably too much overhead.
[Edit 05.11.04]
Fixer sent me the following link & said he had validation of accounts against Exchange up & working within 2 hours. If you are like his net admin (and like most of us using Exchange) and are quite paranoid about the stability of Exchange, this would help reduce the load on Exchange.
http://www.unixwiz.net/techtips/postfix ... users.html
[End Edit]
Be careful in setting the score limits. Its better for users to get some spam (& tell you about it) than it is to get a bunch of false positives. Users will understand some spam getting through, but will not like valid messages getting bounced.
Personally, I've leaned towards putting spam senders into the pcre files I mentioned above. If I know there is some unique identifier in an email (usually a sender address or web link), I'll add it to the postfix. This has two advantages; it reduces load on the server (amavisd never sees the mail), and doesn't fill up the Exchange mailbox you set up with stuff you know is spam. On the other hand, there is no notification.. just a SMTP reject.
You may want to install logrotate to help manage logs. They get big fast. Also, I use mtail to color my logs when I tail them. A simple grep statement & mtail can give you a good visual of how many mails are getting bounced, passed, etc.
If you want configuration files, PM me.
Resources
Scott Henderson's site - where I learned most of this stuff
http://www.geocities.com/scottlhenderso ... ilter.html
Postfix - difficult documentation tho...
http://www.postfix.org/
Amavisd-new - just read the config file
http://www.ijs.si/software/amavisd/
SpamAssasin
http://www.mirror.ac.uk/sites/spamassas ... index.html
SpamAssassin Config Settings - remember, the score settings need to be in amavisd.conf
http://www.mirror.ac.uk/sites/spamassas ... _Conf.html




