How to Add SPF Record to All account on a cPanel/WHM Server

Introduction

This guide explains how to change SPF records for all domains on a server. This can be helpful when adding a new IP address or remote mail server to existing records.

Here’s how to update SPF records for all domains on your server:

 

This command adds an SPF record entry for example.domain.tld to the DNS configuration of all domains hosted on the server.

cat /etc/localdomains | xargs -n 1 /scripts/whoowns | sort | uniq | egrep -v '^$' | xargs -n 1 -I account sh -c 'echo Installing for account...;
/usr/local/cpanel/bin/spf_installer account include:example.domain.tld; echo Done.'

This command includes the IP address 203.0.113.45 in the SPF record for all domains hosted on the server.

cat /etc/localdomains | xargs -n 1 /scripts/whoowns | sort | uniq | egrep -v '^$' | xargs -n 1 -I account sh -c 'echo Installing for account...;
/usr/local/cpanel/bin/spf_installer account +ip4:203.0.113.45; echo Done.'