Applicable to:
- Plesk for Linux
- Plesk for Windows
Question
How to add SPF record for all domains on Plesk server?
Answer
SPF record for all domains can be added as follows:
-
Connect to the server via RDP and open command prompt as Administrator
-
Get the list of domains:
C:\> "%plesk_bin%\dbclient.exe" --direct-sql --sql="SELECT name FROM domains" > dns.txt
-
Add TXT record for all domains as follows:
C:\> for /f "skip=1" %i in (dns.txt); do ("%plesk_cli%\dns.exe" -a %i -txt "v=spf1 some_spf_text")
Note: Change
some_spf_text
by the required record. For more information see: How to create SPF rule for the domain?
-
Connect to the server via SSH
-
Find domains without spf TXT record:
# plesk db -Ne "select name from domains where dns_zone_id not in (select dns_zone_id from dns_recs where type='TXT' and val like '%spf%');" > domains_without_spf.txt
-
Add spf record
# cat domains_without_spf.txt | while read i; do echo $i; plesk bin dns -a $i -txt "some_spf_text" ;done
Note: Change
some_spf_text
by the required record. For more information see: How to create SPF rule for the domain?
Comments
3 comments
How about UPDATING all the SPF records of domains? Since there may be multiple TXT entries for each domain, we can't just delete all the TXT and re-insert them :(
Hello @Turgut Kalfaoglu,
Thank you for your question. You are right, we can't just remove all the TXT type records, because they are not only for SPF. The utility "plesk bin dns" also doesn't have the "update" option. That's why we will need to update the existing records via the database. Below are two options - for Linux and for Windows.
Connect to the server via SSH
Create Plesk database backup
Update the SPF entries in the database:
# plesk db
> UPDATE dns_recs SET val = REPLACE(val, 'v=spf1', 'v=spf1 include:example.com');
> UPDATE dns_recs SET displayVal = REPLACE(displayVal, 'v=spf1', 'v=spf1 include:example.com');
quit
Use the Plesk repair tool kit to repair the DNS:
# plesk repair dns -y
Connect to the server via RDP
Create Plesk database backup
Open the Command line as an Administrator
Update the SPF entries in the database:
C:\> plesk db
> UPDATE dns_recs SET val = REPLACE(val, 'v=spf1', 'v=spf1 include:example.com');
> UPDATE dns_recs SET displayVal = REPLACE(displayVal, 'v=spf1', 'v=spf1 include:example.com');
quit
Use the Plesk repair tool kit to repair the DNS:
C:\> plesk repair dns -y
Just a note to the SQL queries above. These queries replace the old value 'v=spf1' with the new value 'v=spf1 include:example.com' on all domains. Please don't forget to change them to the ones you need.
Thank you very much -- great help!
I had various versions of SPFs already listed, so I got a list of them first:
plesk db "select val from dns_recs where val like '%spf1%';" | sort|uniq > spfs
I edited spfs file so only the bad versions remain, Then I ran this ooRexx I wrote:
/**/
inf = 'spfs'
do while lines(inf)>0
r = strip(linein(inf))
say "UPDATE dns_recs SET val = REPLACE(val, '"r"','v=spf1 mx a ip4:135.181.160.175 ip4:65.21.212.128/29 -all');"
say "UPDATE dns_recs SET displayVal = REPLACE(displayVal, '"r"','v=spf1 mx a ip4:135.181.160.175 ip4:65.21.212.128/29 -all');"
end
I ran this, redirecting its output to a file, and then I fed it to plesk db with something like
plesk db < blah
finally I ran the plesk repair dns -y
Please sign in to leave a comment.