Postfix Postgrey и очистка очереди

Не дают покоя спаммеры факультетской почте. После настройки Яндекс.Спамооборона 1024 спам в ящики практически перестал приходить, но пошла новая тема - вдувать за день в очередь около миллиона корявых сообщений, которые системе приходится обрабатывать и получается, фактически, отказ в обслуживании.

Пришлось подключить к postfix релею policy server Postgrey. Смысл её работы:

When a request for delivery of a mail is received by Postfix via SMTP, the triplet CLIENT_IP / SENDER / RECIPIENT is built. If it is the first time that this triplet is seen, or if the triplet was first seen, less than 5 minutes ago, then the mail gets rejected with a temporary error. Hopefully spammers or viruses will not try again later, as it is however required per RFC.

Тем самым отсекается основной поток одинаковых писем.

Настроить на Ubuntu очень просто:

apt-get install postgrey

И потом добавить нужную директиву к smtpd_recipient_restrictions, например:

smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, check_policy_service inet:127.0.0.1:10023

И перезапустить postfix:

/etc/init.d/postfix reload

После этого не помешает очистить очередь от скопившихся там баунсов. Что бы найти и удалить все письма в очереди от MAILER-DAEMON, я воспользовался скриптом, найденным тут:

#!/bin/bash
mailq | tail -n +2 | grep -v '^ *(' | awk  'BEGIN { RS = "" }
# $7=sender, $8=recipient1, $9=recipient2
{ if ($7 == "MAILER-DAEMON" )
    print $1 }
' | tr -d '*!' | postsuper -d -

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Subscribe without commenting