[AWS MX2(sudo)]:~# sudo apt install fail2ban
[AWS MX2(sudo)]:~# cat /etc/fail2ban/jail.local [DEFAULT] backend = systemd maxretry = 3 findtime = 600 # おすすめ:7日BAN(EC2なら問題なし)→ 無期限に変更 #bantime = 604800 bantime = forever banaction = iptables-multiport # --- Postfix SASL --- [postfix-sasl] enabled = true port = smtp,submission,465 filter = postfix[mode=auth] logpath = %(postfix_log)s # --- Dovecot --- [dovecot] enabled = true port = pop3,pop3s,imap,imaps,submission,465 filter = dovecot logpath = %(dovecot_log)s
[AWS MX2(sudo)]:~# sudo systemctl restart fail2ban [AWS MX2(sudo)]:~# sudo systemctl enable fail2ban Synchronizing state of fail2ban.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable fail2ban
[AWS MX2(sudo)]:~# sudo systemctl status fail2ban
● fail2ban.service - Fail2Ban Service
Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2026-01-08 11:09:35 JST; 9s ago
Docs: man:fail2ban(1)
Process: 28396 ExecStop=/usr/bin/fail2ban-client stop (code=exited, status=0/SUCCESS)
Process: 28397 ExecStartPre=/bin/mkdir -p /var/run/fail2ban (code=exited, status=0/SUCCESS)
Main PID: 28409 (fail2ban-server)
Tasks: 7 (limit: 4680)
CGroup: /system.slice/fail2ban.service
└─28409 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
Jan 08 11:09:35 ip-172-31-22-38 systemd[1]: Stopped Fail2Ban Service.
Jan 08 11:09:35 ip-172-31-22-38 systemd[1]: Starting Fail2Ban Service...
Jan 08 11:09:35 ip-172-31-22-38 systemd[1]: Started Fail2Ban Service.
Jan 08 11:09:35 ip-172-31-22-38 fail2ban-server[28409]: Server readyAWS MX2(sudo)]:~# sudo fail2ban-client status postfix-sasl Status for the jail: postfix-sasl |- Filter | |- Currently failed: 0 | |- Total failed: 0 | `- Journal matches: _SYSTEMD_UNIT=postfix.service `- Actions |- Currently banned: 0 |- Total banned: 0 `- Banned IP list: [AWS MX2(sudo)]:~# sudo fail2ban-client status dovecot Status for the jail: dovecot |- Filter | |- Currently failed: 1 | |- Total failed: 2 | `- Journal matches: _SYSTEMD_UNIT=dovecot.service `- Actions |- Currently banned: 0 |- Total banned: 0 `- Banned IP list:
− 変更するのは /etc/postfix/master.cf の中の記述 --->
master.cf、
main.cf
# # Postfix master process configuration file. For details on the format # of the file, see the master(5) manual page (command: "man 5 master" or # on-line: http://www.postfix.org/master.5.html). # # Do not forget to execute "postfix reload" after editing this file. # # ========================================================================== # service type private unpriv chroot wakeup maxproc command + args # (yes) (yes) (no) (never) (100) # ========================================================================== smtp inet n - y - - smtpd -o smtpd_sasl_auth_enable=no submission inet n - y - - smtpd -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject #smtp inet n - y - 1 postscreen #smtpd pass - - y - - smtpd #dnsblog unix - - y - 0 dnsblog #tlsproxy unix - - y - 0 tlsproxy # SMTP with TLS on port 587. Currently commented. #submission inet n - y - - smtpd # -o syslog_name=postfix/submission # -o smtpd_tls_security_level=encrypt # -o smtpd_sasl_auth_enable=yes # -o smtpd_enforce_tls=yes # -o smtpd_client_restrictions=permit_sasl_authenticated,reject_unauth_destination,reject # -o smtpd_sasl_tls_security_options=noanonymous # SMTP over SSL on port 465. # Intentionally disable 465 port access (=smtps) : 20260108 #smtps inet n - y - - smtpd # -o syslog_name=postfix/smtps # -o smtpd_tls_wrappermode=yes # -o smtpd_sasl_auth_enable=yes # -o smtpd_tls_auth_only=yes # -o smtpd_client_restrictions=permit_sasl_authenticated,reject_unauth_destination,reject # -o smtpd_sasl_security_options=noanonymous,noplaintext # -o smtpd_sasl_tls_security_options=noanonymous
[AWS MX2(sudo)]:~# postconf -e 'compatibility_level = 2' [AWS MX2(sudo)]:~# postfix reload
[AWS MX2(sudo)]:~# postfix check postfix/postfix-script: warning: not owned by root: /etc/postfix/./dkim.key
| 項目 | 変更前 | 変更後 |
| サーバー名 | mail2.hmuna.com | 変更なし |
| ポート | 465 | 587(submission) |
| 接続の保護 | SSL/TLS | STARTTLS |
| 認証方式 | 通常のパスワード認証 | 変更なし |