Prerequisites
Before blocking spam, make sure you have:
- SSH access to your VPS
- Root or sudo privileges
- Postfix or other MTA installed
Method 1: Install and Configure SpamAssassin
Connect to your VPS:
ssh hxroot@YOUR_SERVER_IP -p 22
sudo apt install spamassassin spamc -y
sudo systemctl enable spamassassin
sudo systemctl start spamassassin
Configure Postfix to use SpamAssassin by editing /etc/postfix/master.cf.
Method 2: Use RBLs (Realtime Blackhole Lists) in Postfix
Edit /etc/postfix/main.cf:
smtpd_recipient_restrictions = permit_mynetworks,
reject_rbl_client zen.spamhaus.org,
reject_rbl_client bl.spamcop.net,
permit
Restart Postfix:
sudo systemctl restart postfix
Method 3: Configure Greylisting with postgrey
sudo apt install postgrey -y
sudo systemctl enable postgrey
sudo systemctl start postgrey
In Postfix main.cf add:
smtpd_recipient_restrictions = check_policy_service inet:127.0.0.1:10023
Method 4: Block Common Spam Domains
sudo nano /etc/postfix/access
.spammerdomain.com REJECT
.bad.net REJECT
Create database:
sudo postmap /etc/postfix/access
Method 5: Limit Incoming Email Volume (Rate Limiting)
Add to main.cf:
smtpd_client_message_rate_limit = 10
smtpd_client_recipient_rate_limit = 10
anvil_rate_time_unit = 60s
Method 6: Use Fail2ban for Postfix (Ban abusive IPs)
Create jail in /etc/fail2ban/jail.local:
[postfix]
enabled = true
logpath = /var/log/mail.log
maxretry = 5
bantime = 3600
Restart Fail2ban.
✅ Spam protection configured. Monitor mail logs for effectiveness.