4u123

Well-Known Member
PartnerNOC
Jan 2, 2006
947
29
178
Hi,

I was wondering if someone could possibly advise me on the following...

I'd like to change the MX records of all domains on a server and make sure that those changes are correctly propagated to the cpanel nameservers.

The reason for this is that we will be installing an anti spam appliance which requires the mx record to be changed for any domain that will be using it.

There are two ways to go about that - let the customer do it themselves if they require the new anti spam solution - or do the changes all in one go. On some servers we want to let them do it themselves but on others I'd like to change the MX records for all the domains.

Would you recommend that we write a script to do this - or is there some trickery that could be done form the command line ?

Thanks in advance.
 

4u123

Well-Known Member
PartnerNOC
Jan 2, 2006
947
29
178
Think I've found what I need.

If we can write a script that will update the zone files on the main dns servers, I can then use this utility (zsu) to update the serial numbers so the changes are correctly synchronised

http://www.dns.net/dist/zsu/

The only remaining question is how to change the mx record from the domain name itself to the new appliance hostname...

In the zone file, the mx is written as follows...

domain.net. IN MX 0 domain.net.

the script would have to look for the string "IN MX 0" and then compare the text to the right of that with the text to the left, using the . as a marker to show the end of the string.

If the two values match then it means the MX is currently controlled by cpanel and not externally. If they dont match then it means the MX is already pointing elswhere and that file shouldnt be edited.

So if the string to the left of "IN MX 0" matches the string to the right of it - the string to the right can be replaced with the new hostname.

That sounds pretty straight forward actually.

Can you see any flaws in that ?

edit - I can...

Because of domains containing more than one dot - i.e domain.co.uk. The script would need to determine the end of the string to the right of "IN MX 0" by identifying the final "." - i.e where there is no other character of any kind after it.

would that be possible ?
 
Last edited:

4u123

Well-Known Member
PartnerNOC
Jan 2, 2006
947
29
178
I now have a script that will change the MX records in all the zone files in /var/named - but it will only change the MX records that are pointing directly to the main domain specified in each zone file - so this will not have any effect on MX records that are already pointing externally.

Question....

If I change the records on the main nameservers and update the serials on the files - will all the hosting servers set the domains to remote - i.e add them to the remotedomains file automatically ? If so, How could I prevent that from happening ? We still need the domains to accept mail locally.
 
Last edited:

DomineauX

Well-Known Member
PartnerNOC
Apr 12, 2003
429
11
168
Houston, TX
cPanel Access Level
Root Administrator
I know this is a 3 year old thread but just ran across and wanted to ask if you shared the bulk mx change script you made as I like the way you approached it to only edit the MX if the left and right part of the line matched (domain.tld. and domain.tld.) to avoid disrupting zones using external MX records already.

Also, in case you still wonder, adding the spam filtering appliance under "Configure Remote Service IPs" to have the local server accept mail for the domain still.