• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 696
  • Last Modified:

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.


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.
  • 3
  • 3
1 Solution
Daniel McAllisterPresident, IT4SOHO, LLCCommented:
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...

SystemizeAuthor Commented:
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).
Daniel McAllisterPresident, IT4SOHO, LLCCommented:
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.

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

SystemizeAuthor Commented:
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
Daniel McAllisterPresident, IT4SOHO, LLCCommented:
This may be a cPanel bug, but it essentially comes down to the DNS having to be imported before you tell cPanel to add the domain to your list of hosted domains.

I'm not an expert on cPanel as I am old-school and do most of my admin work command-line, so other than suggesting you find a way to add/import DNS settings BEFORE adding the domain in cPanel, I'm out of ideas.

SystemizeAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now