How to Secure Your Mail Server from Spam and Malware
Maintaining a secure mail server is critical to ensuring that your emails are not compromised by spam or malware. This guide provides detailed step-by-step instructions for QuickServers.net customers, complete with SSH commands and configurations.
Step 1: Enable Spam Filtering Using SpamAssassin
- Install SpamAssassin via SSH:
sudo apt update sudo apt install spamassassin spamc
- Enable and start SpamAssassin:
sudo systemctl enable spamassassin sudo systemctl start spamassassin
- Edit the configuration file to fine-tune spam rules:
Add or modify:sudo nano /etc/spamassassin/local.cf
required_score 5.0 rewrite_header Subject *****SPAM***** use_bayes 1
- Restart SpamAssassin for the changes to take effect:
sudo systemctl restart spamassassin
Step 2: Use Real-Time Blackhole Lists (RBLs)
- Update your mail server's Postfix configuration to use RBLs:
Edit the Postfix main configuration file:
Add:sudo nano /etc/postfix/main.cf
smtpd_recipient_restrictions = reject_rbl_client zen.spamhaus.org, reject_rbl_client bl.spamcop.net, permit
- Reload Postfix:
sudo systemctl reload postfix
Step 3: Enable SPF, DKIM, and DMARC
-
SPF:
Add an SPF TXT record to your domain's DNS:v=spf1 mx a ip4:your_server_ip -all
-
DKIM:
Install OpenDKIM:sudo apt install opendkim opendkim-tools
Configure OpenDKIM to sign outgoing emails:
sudo nano /etc/opendkim.conf
Add or modify:
AutoRestart Yes Mode sv Canonicalization relaxed/simple KeyTable /etc/opendkim/key.table SigningTable /etc/opendkim/signing.table
Generate a DKIM key pair and publish the public key in your DNS.
-
DMARC:
Add a DMARC TXT record to your domain's DNS:_dmarc.yourdomain.com IN TXT "v=DMARC1; p=none; rua=mailto:admin@yourdomain.com"
Step 4: Install Antivirus Software
- Install ClamAV:
sudo apt install clamav clamav-daemon
- Update virus definitions:
sudo freshclam
- Configure Postfix to scan emails using ClamAV.
Step 5: Use Secure Connections (TLS/SSL)
- Configure Postfix to enforce TLS encryption:
Add:sudo nano /etc/postfix/main.cf
smtpd_tls_cert_file=/path/to/certificate.crt smtpd_tls_key_file=/path/to/private.key smtpd_use_tls=yes
- Restart Postfix:
sudo systemctl restart postfix
Step 6: Implement Greylisting
- Install and configure a greylisting tool like Postgrey:
sudo apt install postgrey
- Enable Postgrey in Postfix:
Add:sudo nano /etc/postfix/main.cf
smtpd_recipient_restrictions = check_policy_service inet:127.0.0.1:10023
Step 7: Restrict Open Relay
- Ensure your Postfix configuration restricts relaying:
Confirm:sudo nano /etc/postfix/main.cf
relay_domains = smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
Step 8: Monitor Mail Server Logs
- Use SSH to review mail server logs:
sudo tail -f /var/log/mail.log
- Look for patterns indicating potential issues, such as repeated failed logins.
By following these detailed steps, you’ll secure your mail server effectively against spam and malware. For more assistance, visit QuickServers.net.