Docs / Email Servers / SPF, DKIM, and DMARC Configuration Guide

SPF, DKIM, and DMARC Configuration Guide

By Admin · Feb 6, 2026 · Updated Apr 23, 2026 · 5 views · 4 min read

In this article, we'll walk through the complete process of working with spf in a server environment. Understanding dkim is essential for maintaining a reliable and performant infrastructure.

Prerequisites

  • A VPS running Ubuntu 22.04 or later (2GB+ RAM recommended)
  • Valid PTR (reverse DNS) record configured
  • A clean IP address not on any blacklists
  • Root or sudo access to the server
  • A registered domain name (for public-facing services)

Server Installation

Regular maintenance is essential for keeping your spf installation running smoothly. Schedule periodic reviews of log files, disk usage, and security updates to prevent issues before they occur.


# Install Postfix and Dovecot
sudo apt update
sudo apt install -y postfix dovecot-core dovecot-imapd dovecot-lmtpd

# Configure Postfix main.cf
sudo postconf -e 'myhostname = mail.example.com'
sudo postconf -e 'mydomain = example.com'
sudo postconf -e 'smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem'
sudo postconf -e 'smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem'

The output should show the service running without errors. If you see any warning messages, address them before proceeding to the next step.

  • Use connection pooling for database connections
  • Start with the minimum required resources
  • Implement caching at every appropriate layer
  • Profile before optimizing - measure first
  • Scale vertically before scaling horizontally

Authentication Setup (SPF/DKIM)

For production deployments, consider implementing high availability by running multiple instances behind a load balancer. This approach provides both redundancy and improved performance under heavy load.


# Generate DKIM key
sudo apt install -y opendkim opendkim-tools
sudo mkdir -p /etc/opendkim/keys/example.com
sudo opendkim-genkey -b 2048 -d example.com -D /etc/opendkim/keys/example.com -s default -v

# Add the DNS TXT record from:
cat /etc/opendkim/keys/example.com/default.txt

This configuration provides a good balance between performance and resource usage. For high-traffic scenarios, you may need to increase the limits further.

Advanced Settings

When scaling this setup, consider vertical scaling (adding more RAM/CPU) first, as it's simpler to implement. Horizontal scaling adds complexity but may be necessary for high-traffic applications.

  • Monitor disk space usage and set up alerts
  • Review log files weekly for anomalies
  • Enable automatic security updates for critical patches
  • Keep your system packages updated regularly
  • Test your backup restore procedure monthly

Client Configuration

Before making changes to the configuration, always create a backup of the existing files. This ensures you can quickly roll back if something goes wrong during the setup process.


# Install Postfix and Dovecot
sudo apt update
sudo apt install -y postfix dovecot-core dovecot-imapd dovecot-lmtpd

# Configure Postfix main.cf
sudo postconf -e 'myhostname = mail.example.com'
sudo postconf -e 'mydomain = example.com'
sudo postconf -e 'smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem'
sudo postconf -e 'smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem'

This configuration provides a good balance between performance and resource usage. For high-traffic scenarios, you may need to increase the limits further.

Spam Filtering

The dkim component plays a crucial role in the overall architecture. Understanding how it interacts with spf will help you make better configuration decisions.


# Generate DKIM key
sudo apt install -y opendkim opendkim-tools
sudo mkdir -p /etc/opendkim/keys/example.com
sudo opendkim-genkey -b 2048 -d example.com -D /etc/opendkim/keys/example.com -s default -v

# Add the DNS TXT record from:
cat /etc/opendkim/keys/example.com/default.txt

Note that file paths may vary depending on your Linux distribution. The examples here are for Debian/Ubuntu; adjust paths accordingly for RHEL/CentOS-based systems.

Wrapping Up

Following this guide, your spf setup should be production-ready. Keep an eye on resource usage as your traffic grows and don't forget to test your backup and recovery procedures periodically.

Was this article helpful?