Mass Update SPF Records On cPanel Servers
Usually, when you migrate accounts using the Transfer Tool in WHM the DNS records are updated automatically. Records like SPF values are updated to the new servers IP so no manual configuration is required. But there are cases where you will need to mass update some records like SPF ones.
If you are connecting your cPanel server to a SmartHost you will need to update the SPF records on all domain names or it’s likely your SmartHost’s IP will get listed in RBLs like SpamCop. In our Exim series of articles, we created an Exim mail server and used that as a SmartHost. We connected our development cPanel server to our SmartHost relay. Now we will update the SPF record in our development server using SSH. You can use this guide to update one domain names SPF or 1000.
Mass Update SPF Records
First, let’s check our current SPF record. The IP of our SmartHost was 148.251.220.14 so this needs to be reflected in the SPF record.
dig txt first2host.org
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.3 <<>> txt first2host.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63051
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;first2host.org. IN TXT
;; ANSWER SECTION:
first2host.org. 14399 IN TXT "v=spf1 +a +mx +ip4:54.36.0.57 ~all"
;; Query time: 29 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Feb 25 11:18:35 GMT 2021
;; MSG SIZE rcvd: 90
We can see from the report that the current SPF record only reflects our development servers IP. So we need to update this. Let’s first copy thee named folder so we can restore it should we need to.
cp -a /var/named /var/named-backup
Then move into the named folder so we can run the command to update the SPF
cd /var/named
Now we can run the command to update the SPF records on all the zone files in this folder. This will update the record for ALL domain names on the server. If you just wanted to edit one. Open up the file using a text editor and edit the value manually.
find /var/named -type f -exec sed -i 's/+ip4:54.36.0.57/+ip4:148.251.220.14/gI' {} \;
systemctl restart named
The command above will search for the string +ip4:54.36.0.57 and replace it with +ip4:148.251.220.14. The command searches all files in the /var/named folder allowing you to mass update the SPF for all domain names.
Updating A Single SPF Record
If you just wanted to update a single SPF record then you could use the following command
sed -i 's/+ip4:54.36.0.57/+ip4:148.251.220.14/g' /var/named/first2host.org.db
systemctl restart named
This would change the SPF record for the first2host.org domain name from 54.36.0.57 to our SmartHost’s IP of 148.251.220.14.
Verify SPF Update
Finally to double-check the SPF record is now correct you cag dig the txt record like we did at the start.
dig txt first2host.org
dig txt first2host.org
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.3 <<>> txt first2host.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42459
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;first2host.org. IN TXT
;; ANSWER SECTION:
first2host.org. 14399 IN TXT "v=spf1 +a +mx +ip4:148.251.220.14 ~all"
;; Query time: 28 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Feb 25 12:41:26 GMT 2021
;; MSG SIZE rcvd: 94
How was this article? Bulk Update SPF Records On cPanel Servers
You might also like
More from cPanel
How To Install A Cloudflare Origin SSL Certificate In cPanel
Free SSL Certificates from places like cPanel or Let's Encrypt are great. When Let's Encrypt first introduces free SSL Certificates …
Create a SWAP partition on CentOS, RHEL and AlmaLinux without a reboot
SWAP is a memory type that Linux NVMe VPS Servers use to process requests. Memory will be held in SWAP …
Help fixing Error: last request failed: [AUTH] Authentication failed.
The Error: last request failed: [AUTH] Authentication failed error can be caused by a range of things. It could be …
1 Comment
[…] Mass Update SPF Records […]