PowerDNS/DNS Cluster
2025-11-07 15:40:12
Published By
KhalequzzamanSMTP Relay Setup Guide (AlmaLinux 8 + cPanel Integration)
PART 1: Setup the SMTP Relay Server (AlmaLinux 8)
You’ll use Postfix as the relay (stable, simple, and widely supported).Step 1 – Install Postfix
Run the following commands on your AlmaLinux VPS:dnf install -y initscripts
dnf install -y postfix
systemctl enable postfix
systemctl start postfix
Step 2 – Configure Postfix as a Relay Host
Edit the main configuration file:nano /etc/postfix/main.cf
Set or modify the following lines:
myhostname = eostre.names4u.win
mydestination =
relay_domains = *
mynetworks = 127.0.0.0/8, 163.61.30.92/32
inet_interfaces = all
inet_protocols = ipv4
Then restart Postfix:
systemctl restart postfix
Check for errors:
postfix check
No output means the configuration is valid. Your AlmaLinux VPS now acts as a basic relay, accepting mail only from your cPanel server IP.
Step 3 – Confirm Postfix Settings
Check the allowed networks:postconf mynetworks
Expected output:
mynetworks = 127.0.0.0/8, 163.61.30.92/32
Step 4 – Verify Listening Ports
Ensure Postfix is listening on port 25 (and optionally 587):ss -tulpn | grep master
Expected output:
tcp LISTEN 0 100 0.0.0.0:25 0.0.0.0:* users:(("master",pid=1234,fd=13))
To confirm which ports are defined in Postfix:
grep -E '^[^#].*(smtp|submission)' /etc/postfix/master.cf
Expected lines:
smtp inet n - n - - smtpd
submission inet n - n - - smtpd
- smtp → Port 25 is active
- submission → Port 587 is active (if not commented)
(Optional) Enable Port 587
If 587 is commented out, edit:nano /etc/postfix/master.cf
Uncomment or add:
submission inet n - n - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=may
-o smtpd_sasl_auth_enable=no
-o smtpd_relay_restrictions=permit_mynetworks,reject_unauth_destination
-o smtpd_recipient_restrictions=permit_mynetworks,reject_unauth_destination
Restart Postfix:
systemctl restart postfix
Verify:
ss -tulpn | grep master
Expected:
tcp LISTEN 0 100 0.0.0.0:25
tcp LISTEN 0 100 0.0.0.0:587
PART 2: Configure the cPanel Server (Crater)
Step 5 – Update Exim Route
In WHM: WHM → Exim Configuration Manager → Advanced Editor Find the PREROUTERS section and add:smarthost_route:
driver = manualroute
domains = ! +local_domains
transport = remote_smtp
route_list = * eostre.names4u.win::587
no_more
Step 6 – Test the Connection
Run from the cPanel server:nc -vz eostre.names4u.win 587
Expected:
Connection to eostre.names4u.win 587 port [tcp/submission] succeeded!
Then test mail queue and delivery:
exim -qf
tail -f /var/log/exim_mainlog
On the relay VPS:
tail -f /var/log/maillog
You should see your relay accepting connections from the cPanel server and queuing mail.Rebuild and restart Exim:
/scripts/buildeximconf
/scripts/restartsrv_exim
Test with:
echo "Relay test successful" | mail -s "Relay Test" [email protected]
PART 3: Configure SPF Records
Step 7 – Create Central SPF Include
On your primary DNS zone (names4u.win), add:| Name | Type | Value |
|---|---|---|
| _spf | TXT | v=spf1 ip4:163.61.30.92 ip4:173.249.215.35 +a +mx ~all |
dig txt _spf.names4u.win
Expected:
"_spf.names4u.win. IN TXT "v=spf1 ip4:163.61.30.92 ip4:173.249.215.35 +a +mx ~all""
Step 8 – Automatic SPF for New Domains
Edit the cPanel zone template:nano /usr/local/cpanel/etc/zonetemplates/standard
Add this at the bottom:
%domain%. IN TXT "v=spf1 include:_spf.names4u.win ~all"
Optionally also update:
/usr/local/cpanel/etc/zonetemplates/standardvirtualftp
Rebuild DNS config:
/scripts/rebuilddnsconfig
From now on, every new or addon domain will include the unified SPF record automatically.
Step 9 – Update SPF for Existing Domains
9.1 List All cPanel Accounts
whmapi1 listaccts --output=json | jq -r '.data.acct[].domain'
9.2 Update SPF in Zone Files
for domain in $(whmapi1 listaccts --output=json | jq -r '.data.acct[].domain'); do
zonefile="/var/named/${domain}.db"
if [ -f "$zonefile" ]; then
cp "$zonefile" "$zonefile.bak"
if grep -q 'v=spf1' "$zonefile"; then
sed -i 's/v=spf1.*/v=spf1 include:_spf.names4u.win ~all"/' "$zonefile"
echo "Updated SPF in $domain"
else
echo "$domain. IN TXT \"v=spf1 include:_spf.names4u.win ~all\"" >> "$zonefile"
echo "Added SPF to $domain"
fi
else
echo "No local zone file for $domain (managed by DNS cluster or Cloudflare)"
fi
done
9.3 Restart PowerDNS
systemctl restart pdns
9.4 Sync to DNS Cluster
/scripts/dnscluster syncall
Step 10 – Verification
10.1 Local Check
dig txt adiyanbd.com @127.0.0.1
Expected:
"v=spf1 include:_spf.names4u.win ~all"
10.2 Global Check (After TTL ~4 hours)
dig txt adiyanbd.com @8.8.8.8
Step 11 – For Domains on Cloudflare or External DNS
If the domain uses external nameservers (e.g., Cloudflare):cPanel cannot update DNS automatically for such domains.Add manually in Cloudflare:
| Name | Type | Value |
|---|---|---|
| @ | TXT | v=spf1 include:_spf.names4u.win ~all |
Your setup is complete!
- AlmaLinux VPS is configured as a secure SMTP relay.
- cPanel server routes mail via this relay.
- SPF is centralized and auto-managed for all domains.