Installing Greylisting via RelayDelay
I am extremely grateful to Evan Harris and the community who have provided this tool for reducing spam input. These are notes from the procedure I followed for three different systems one weekend. Be sure to consult the INSTALL file from the relaydelay distribution first and foremost.
Here is a snapshot of my MRTG output the week I installed the greylist (got it working Saturday about noon):
The green represents the mail being rejected by spamassassin, and the blue is my total mail volume. Others have produced more valid statistical analyses, but I find the graphic compelling. Now you should be really stoked to get this working. Let's begin:
Obtain the relaydelay archive file from http://projects.puremagic.com/greylisting/releases/
Install the "sendmail-devel-x.y.z.i386.rpm" RPM that is compatible with your system.
Install or upgrade the MySql server. Version 4.02 or later is recommended. For example:
If you are installing the server for the first time, follow the instructions that whiz by during the server RPM install. Basically, you need to set a root user and password and make sure that my.cnf in the /etc directory has all the options you need. I used the file /usr/share/mysql/my-medium.cnf as a basis, your needs may vary.
Install or upgrade some Perl modules, using RPMs or CPAN. I used the CPAN approach.
perl -MCPAN -e 'install DBI'
perl -MCPAN -e 'get DBD::mysql' cd /root/.cpan/build/DBD-mysql-2.9003 perl Makefile.PL --testpassword="yourpassword" --testuser="root" make install (You should delete any files in this directory tree containing your password after the build)
perl -MCPAN -e 'install Net::daemon'
perl -MCPAN -e 'get Sendmail::Milter' cd /root/.cpan/build/Sendmail-Milter-0.18 perl Makefile.PL /usr /usr/lib make install
Untar the relaydelay archive:
tar -zxvf relaydelay-0.04.tgz
Change to the output directory:
Edit the mysql.sql file to supply the correct username and password for the mysql database supporting the greylist. Then Initialize the database:
mysql -p < mysql.sql
I have no idea how you are supposed to use the supplied script, "relaydelay.sh", to start relaydelay.pl. On my system the script hangs at the part where relaydelay.pl is launched, and even if I start it as a background task, nothing works. Fortunately, a patch exists, courtesy of Martin Walker from the greylist-users mailling list, which fixes up the perl script to run properly as a daemon. It even supplies an init script to get things going at bootup. And, even better, it lets you direct output from the perl script into a log file. Get the patch for daemonizing relaydelay from:
The original post by the author of the patch is at:
In case the original location disappears, I've put a copy of the patch here.
Copy the patch to the relaydelay-0.04 directory and run it:
patch -p1 < relaydelay.patch
This will create a script named relaydelay which you should place in your initscripts (/etc/rc.d/init.d) folder. Make sure it is marked executable. At this point you can also copy the relaydelay.pl script into your /usr/sbin directory.
Edit the relaydelay.conf file to set the username and password to be the same as in mysql.sql. Also set the values for $verbose, $run_as_daemon, and $log_file as needed. For beginning use, I also recommend that the value $delay_mail_secs be set to -1, which lets servers retry immediately. Copy this file to your /etc/mail directory, make sure it is executable, and add it to your startup with:
> chkconfig --add relaydelay
Now start up relaydelay:
> /etc/rc.d/init.d/relaydelay start
Verify correct startup:
> ps -A|grep relaydelay.pl
6387 ? 00:00:00 relaydelay.pl
> tail /var/log/relaydelay.log
Loaded Config File: /etc/mail/relaydelay.conf Using connection 'local:/var/run/relaydelay.sock' for filter relaydelay DBI Connecting to DBI:mysql:database=relaydelay:host=localhost:port=3306 Spawned relaydelay daemon process 2229. Starting Sendmail::Milter 0.18 engine.
Add the following line to sendmail.mc:
INPUT_MAIL_FILTER(`relaydelay', `S=local:/var/run/relaydelay.sock, T=S:1m;R:2m;E:3m')dnl
Now restart sendmail. Watch the output in maillog and relaydelay.log to verify correct operation.
Edit whitelist.txt. Change the entry for 192.168 to the more limited value for your subnet (i.e. 192.168.10). I suggest removing the other private network entries here.
Get the script for importing whitelist and blacklist text files:
If you got the script from the puremagic mailing list, edit it to add "my $run_as_daemon" and "my $log_file" to the variable list.
Import the supplied whitelist and blacklist:
perl addlist.pl -whitelist 9999-12-31 23:59:59 < whitelist_ip.txt perl addlist.pl -blacklist 9999-12-31 23:59:59 < blacklist_ip.txt
Now keep an eye on things for awhile. At some point you should arrange for logfile rotation. There is a file here which you can drop into your logrotate.d directory.
Mayn Idea and the M-Light logo are trademarks of Mayn
Last modified 01 Aug 2009