Link to home
Start Free TrialLog in
Avatar of Systemize
Systemize

asked on

cPanel automatic mail routing - showing mail as local when it always remote

When I add a new domain via a script, cPanel's "automatic
routing" always thinks it is in Local domains, despite the MX records
being external.

I have found that I can use a PHP script to automatically move a new domain
from the localdomains file to the remotedomains file but permissions keep
reverting back.

The code I use is:

exec("sed -i '/^".$domain."$/d' /etc/localdomains");
exec("echo '".$domain."' >> /etc/remotedomains");

The permissions command I use is:

chmod 775 /etc/localdomains
chmod 775 /etc/remotedomains
chgrp nobody /etc/remotedomains
chgrp nobody /etc/localdomains

I'm looking to either:

(Preferable) 1) Determine why cPanel automatic domain routing is set to local when cpanel states that automatic routing is only local if the MX records are pointed to the local machine (they are not, they are always pointed to external servers from the start)

Unfortunately logging into cPanel and selecting the "Remote" option is not an option as staff do not have access to this section.

or

2) Determine how I can successfully run the above commands to move a domain from localdomains to remotedomains via my PHP script that staff are running. (in a way that does not compromise security of these files)

Thank you so much.

Additional information:
I am also aware of using /scripts/checkalldomainsmxs but this is something that would need to be run on a cron so any time between that cron would have improper mail settings so it is not an acceptable way to do it for us.
Avatar of Daniel McAllister
Daniel McAllister
Flag of United States of America image

OK, so this post got flagged as neglected -- so I'll take a stab at it...

The first thing is, we need to know which mailserver you're using (cPanel is just a generic config tool -- it can configure sendmail, qmail, postfix, exim, and probably more kinds of mail servers as well).

The next issue is "why" -- why are you "adding" domains into your config that are remote? Are you just trying to short-circuit the normal routing? (In most cases, you don't enter anything for "outside" domains -- and they default to using DNS MX records for mail delivery data).

If we can get through these first 2 questions, I should have some idea in which way this question is going...

Dan
IT4SOHO
Avatar of Systemize
Systemize

ASKER

Hello it4soho,

Thank you very much for your assistance.

Our process is we build websites for our clients that we host on a Wordpress multisite install on our server. They point their nameservers to us and we point the settings to wherever there mail is, etc. (Yes, an A record would do in most scenarios but they won't like that because if they want DNS changes later they want us to be able to make them).

We add the domain as an addon domain but for some reason cPanel defaults the mail routing to local even though their own documentation says that when mail setting are set to auto they will look to see if the MX records are on a local IP, if not, they will set it to Auto (Remote). When we look at a domain's mail routing it says Auto (Local).
OK, I think I've got the picture -- but I think what's happening is that the DNS entries you're making locally are overriding the Internet DNS entries.

So let's start from the basics:
 - You register a domain name at a registrar
 - You create a DNS service for that domain (likely at the registrar)
... time passes until the client calls you
 - You change DNS service to your system (hopefully importing records?)
    HERE is likely where you're getting things wrong -- the initial population of the LOCAL DNS is likely to indicate YOU are the mailserver (well, IT is anyway)...
 - You create a web service at your site (wordpress)
    HERE is another likely place to break -- if you haven't already taught YOUR DNS SERVER to use the OLD MX records, they'll be set for internal delivery... and if you've left the MX records BLANK, you'll also add the domain to local delivery -- as-if it were a "private" domain.
 - You modify the registrar's records to use YOUR DNS servers
 - Mail service breaks -- because the MX records aren't right -- either in your DNS, or in the registrars.

Now, I've probably got at least 1 detail wrong in there -- but you should get the gist of the matter... I think that at the time you add the domain hosting in cPanel, your local DNS is set to be authoritative for domain, but doesn't have (or doesn't have the right) MX records for said domain.

Let me know if this scenario is really what's happening, and if so we can talk about re-ordering how you add domains to make it work right.

Dan
IT4SOHO
Yes that is pretty much the process.

1) Client buys domain, DNS defaults to registrar - or client already has domain and mail settings

Eventually client says they are ready to go live...

2) We add domain as an addon domain domain and import existing settings in case they have email

3) If they don't have MX records we default them to GoDaddy since odds are that is where email is with our client base

4) If we go to WHM and Edit DNS and scroll down to bottom, the DNS page it will show Mail Routing as Automatic (Local) instead of Automatic (Remote). If we change it Local and save, everything is fine. If we don't, any email our server sends will fail because it tried to look locally for email hosting.

If we look at /etc/localdomains it is listed in that file
ASKER CERTIFIED SOLUTION
Avatar of Daniel McAllister
Daniel McAllister
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't believe an addon domain can be made if the .db file exists in /etc/named but I will look into this. Thank you very much for your assistance so far. I will return with more info.