- Ubuntu 20.04
- saslauthd 2.1.27
- fail2ban 0.11.1
SASL(SMTP-AUTH)
sudo apt -y install sasl2-bin
Postfixユーザー を sasl 認証グループに加える
adduser postfix sasl
Postfix の設定可能オプションを有効化する
[master.cf]
submission inet n - y - - smtpd -o syslog_name=postfix/submission -o smtpd_sasl_auth_enable=yes -o smtpd_recipient_restrictions= -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
有効化したオプションの設定値
[main.cf]
smtpd_sasl_auth_enable = yes smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination
[/etc/postfix/sasl/smtpd.conf] (create)
pwcheck_method: saslauthd mech_list: plain login
[/etc/default/saslauthd] (change)
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"
- SMTP-AUTH の接続テスト
perl -MMIME::Base64 -e 'print encode_base64("test\0test\0test");' telnet localhost 587 EHLO mail.example.com ~ AUTH PLAIN dGVzdAB0ZXN0AHRlc3Q= 235 2.7.0 Authentication successful
sudo systemctl enable saslauthd
fail2ban for SMTP-AUTH
sudo apt -y install fail2ban
[jail.local]
bantime = -1 findtime = 86400 maxretry = 3 destemail = test@example.com sender = fail2ban@example.com mta = postfix [postfix-sasl] enabled = true mode = aggressive ignoreip = 127.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8
(設定ファイルについて)
設定ファイルは「jail.conf」ではなく「jail.local」で行うとよい。
conf ファイルはアップデート時に上書きされる可能性があるらしい。
また、動作的に conf ファイルは local ファイルで上書きされる。
(設定の概要)
永久BANにして、メール飛ばして、ignoreipでホワイトリストを書く。
mode の詳細については filter.d/postfix.comf
を見る方が早い。
https://github.com/fail2ban/fail2ban/blob/master/config/filter.d/postfix.conf
sudo systemctl restart fail2ban sudo systemctl enable fail2ban
- fail2ban 各コマンド
sudo fail2ban-client status postfix-sasl sudo fail2ban-client set postfix-sasl banip xxx.xxx.xxx.0/24 sudo fail2ban-client set postfix-sasl unbanip xxx.xxx.xxx.123