How to update an SPF record for all domains that already have a particular record?
Answer
Note: it is necessary to delete existing SPF DNS records before creating new ones via CLI.
It may take considerable time to apply the changes even for a single domain.
Plesk for Windows
-
Connect to the server via RDP
-
From a Command Prompt (cmd) create a list of all domains that contain a specific SPF record, e.g.
specific_record
:C:> plesk db -Ne "SELECT d.name FROM domains AS d, dns_zone AS z, dns_recs AS r WHERE d.name=z.name AND z.id=r.dns_zone_id AND r.type='txt' AND val LIKE '%specific_record%';" > domains.txt
-
Delete all SPF records containing the
specific_record
value from the list of domains:C:> for /f %i in (domains.txt) do "%plesk_cli%dns.exe" -d %i -txt "specific_record"
If the following output is received for some line, safely ignore it:
Unable to del record in DNS server: unable to find DNS record
-
Create new SPF records for domains in the same list, e.g.
new_spf_record
:C:> for /f %i in (domains.txt) do "%plesk_cli%dns.exe" -a %i -txt "new_spf_record"
Plesk for Linux
-
Connect to the server via SSH;
-
Create a list of domains:
# plesk bin domain --list > domains.txt
-
Remove all specific SPF records (e.g. "
specific record
") from ALL domains:# for i in $(cat domains.txt); do plesk bin dns -d $i -txt "specific record"; done
-
Add the new SPF record (e.g. "
new spf record
") as follows:# for i in $(cat domains.txt); do plesk bin dns -a $i -txt "new spf record"; done