• Plesk Uservoice will be deprecated by October. Moving forward, all product feature requests and improvement suggestions will be managed through our new platform Plesk Productboard.
    To continue sharing your ideas and feedback, please visit features.plesk.com

Question Change MX record with Plesk CLI

TorbHo

Regular Pleskian
Server operating system version
Ubuntu 24
Plesk version and microupdate number
18.0.71 Update 2
I would like to update the MX record for all domains on my Plesk server so that they all point to the same new mail server. Ideally, I’d like to do this in one go via the Plesk CLI (e.g. using plesk bin dns) instead of editing each domain individually.


From what I’ve read so far, it doesn’t seem possible to replace an existing MX record directly — it looks like you first need to remove the old one and then add the new MX record. Is that correct?


Has anyone already done this or maybe has a sample script to automate it?
 
Depending on your exact objectives, it might be easier to change the MX record in the DNS template (Tools & Settings > DNS Settings) and apply the changed DNS template. It's worth pointing out that modified DNS records are never updated when applying the DNS template. So if there are any modified MX records on some domain, those probably have to be updated manually (via gui or script).

You can use the Plesk CLI to update all MX records, but this support article outlines a easier method: https://support.plesk.com/hc/en-us/...date-the-IP-address-in-multiple-DNS-A-records

If you do want to use CLI, this post has an example you can use. With CLI you do need separtely delete the old record and add a new one (there is no update method).
 
We are using a primary DNS server that manages all domains as an authoritative DNS-only server. On that server, we cannot simply adjust the DNS template because it holds many different MX records for different domains. The primary DNS server distributes the DNS entries to other DNS servers (Bind9) via the Slave-DNS extension.

Because of this, I wrote a Bash script that iterates through all domains and checks which ones use a specific MX record. For those, I’d like to change the MX to a new one.

Thanks to your link. I will try something like this:
Code:
plesk bin dns -d \"$domain\" -mx <subdomain> -mailexchanger ${OLD_MX%.}
plesk bin dns -a \"$domain\" -mx <subdomain> -mailexchanger ${NEW_MX%.}
 
Back
Top