在 Debian 上部署邮件服务器(如 Postfix、Dovecot、Roundcube 等)时,防攻击非常重要。下面从 系统层、邮件服务层、认证层、网络层、监控与审计 等角度,给你一套实战可用的防护方案。
apt update && apt upgrade -y
# /etc/ssh/sshd_config
PermitRootLogin no
Port 22222
PasswordAuthentication no
✅ 严禁 Open Relay
Postfix 配置示例:
smtpd_relay_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination
检查:
postconf smtpd_relay_restrictions
smtpd_client_connection_count_limit = 5
smtpd_client_connection_rate_limit = 20
smtpd_client_message_rate_limit = 50
smtpd_helo_required = yes
smtpd_helo_restrictions =
permit_mynetworks,
reject_invalid_helo_hostname,
reject_non_fqdn_helo_hostname
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination,
reject_invalid_hostname,
reject_non_fqdn_sender,
reject_non_fqdn_recipient
apt install fail2ban -y
/etc/fail2ban/jail.local
[postfix]
enabled = true
port = smtp,submission
filter = postfix
logpath = /var/log/mail.log
maxretry = 5
bantime = 3600
[dovecot]
enabled = true
port = imap,imaps,pop3,pop3s
filter = dovecot
logpath = /var/log/mail.log
maxretry = 5
smtpd_tls_auth_only = yes
DNS 示例:
v=spf1 mx -all
apt install opendkim opendkim-tools
验证:
opendkim-testkey -d example.com -s default
v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com
apt install nftables
限制 SMTP 连接频率(示例):
nft add rule inet filter input tcp dport 25 limit rate 20/minute accept
message_size_limit = 20MB
mailbox_size_limit = 512M
grep "reject" /var/log/mail.log
grep "auth failed" /var/log/mail.log
避免日志被写满
| 攻击类型 | 防护措施 |
|---|---|
| 开放中继 | smtpd_relay_restrictions |
| 暴力破解 | Fail2ban |
| 垃圾邮件 | SPF / DKIM / DMARC |
| 邮件炸弹 | 限制大小 + 频率 |
| DoS | 防火墙 + 连接限制 |
| 账号被盗 | 强密码 + TLS |
✅ Debian + Postfix + Dovecot + Fail2ban + SPF/DKIM + TLS
如果你愿意,我可以:
你可以直接贴出:
cat /etc/postfix/main.cf