i'm running a DNS-server for example.com, with multiple A/CNAME records pointing to different IP-addresses.

@           IN      A
a           IN      A
b           IN      CNAME  a
c           IN      A

now i would like to run a single mail-server (e.g. mail.example.com) for the toplevel domain (joe@example.com) and all hosts within that domain (jane@a.example.com, office@c.example.com)

i imagined something like

@           IN  MX  10  mail
*           IN  MX  10  mail
mail        IN  A

now the above works good enough for the main domain:

$ dig mx example.com | grep MX
;example.com.         IN MX
example.com.          IN MX 10 mail.example.com.

but it doesn't work for the A/CNAME records:

$ dig mx a.example.com | grep MX
;a.example.com.         IN MX

instead, the wildcard * is interpreted literally:

$ dig mx '*.example.com' | grep MX
;*.example.com.         IN MX
*.example.com.   604800 IN MX 10 mail.example.com.

it seems that the way to go would be to have an MX record for each host within the domain:

@           IN      MX  10  mail
a           IN      MX  10  mail
b           IN      MX  10  mail
c           IN      MX  10  mail

now imagine i have hundreds of hosts in my domain... adding an identical MX record for each of them seems to be quite error-prone.

is there a way to specify a single MX entry for all A/CNAME records of a domain?

i'm aware of similar questions on serverfault, e.g. MX Record for SubDomains, but the answer seems to only handle the case, were all hosts resolve to the same IP address, which is not the case here.

;; I cannot use this!
@           IN      A
*           IN      CNAME  @

bonus question

if there is such a way, is it also possible to specify MX records for specific records? e.g. all hosts shall use mail.example.com, only c.example.com shall use mail.c.example.com?


to summarize, i would like to avoid having an MX record for each A/CNAME record in my domain.

e.g. i want to avoid the following:

@           IN      A
@           IN      MX 10  mail
a           IN      A
a           IN      MX 10  mail
b           IN      CNAME  a
b           IN      MX 10  mail
c           IN      A
c           IN      MX 10  mail
mail        IN      A
  • Have you look at Bind Includes? zytrax.com/books/dns/ch8/include.html – NickW Dec 12 '13 at 14:00
  • 1
    i did have a cursory glance, though i didn't see any benefit for my problem. i really try to avoid having to specify an explicit MX record for each A-record, whether this is in a single zone-file or in myriards of per-host snippets. – umläute Dec 12 '13 at 14:05
  • What I'd suggest is having a file, maybe with the NS records, and the MX record, then you could include it everywhere, and avoid filling in an MX record for each. It's not perfect obviously, but it does make adjusting all those records quite simple. – NickW Dec 12 '13 at 14:09
  • 1
    @NickW i understand; i think should have avoided the use of "subdomains" in my question (i've updated the Q); i'm really talking about a single domain with multiple A/CNAME records; and i want the MX-record for each A/CNAME record to point to the same host – umläute Dec 12 '13 at 14:16
  • Ah, yeah, now that makes more sense as to why.. sorry to have wasted your time :) – NickW Dec 12 '13 at 14:27

Wildcards only apply to FQDNs which do not exist as any type of RR. Since you have a A Record for "a.example.com", a wildcard of any RR Type will never match "a.example.com". Sounds like you're already on top of the alternates; mainly manually generating each record or using some convoluted include system.

One other thing to mention, if a domain doesn't have a MX record, but does have an A record a mail exchanger should try that A record for e-mail service. All the major e-mail software I've seen does this.

  • well, if i remember the RFC correctly, an MTA must try that A-record if there is no MX-record. that's exactly why i want to set the MX record for each A-record. – umläute Dec 12 '13 at 14:41
  • "should" and "must" are kind of the same thing when nobody's enforcing it – Chris S Dec 12 '13 at 16:28
  • RFCs have a very clear distinction between should and must (and while technically nobody ever *enforces an RFC, they still use these words and insist that they are different). in any case, this aspect of your answer isn't really related to my question anyhow... (so sorry for being anal) – umläute Dec 12 '13 at 16:50
  • the thing is, that while i understand the reasons why wildcards don't apply here (thanks for clarifying it, anyhow), it doesn't help answering my question. worse: most of the domains i administer have the same problem... so i figure that others might have this problem as well and there ought to be a simple solution for it – umläute Dec 12 '13 at 16:53
  • In the dozen years that I've done DNS administration I've never heard of anyone wanting to do what you're asking. So, I have the inkling that it's more rare than you'd think. If I had to take a while guess you're doing free DNS, like dyndns/no-ip/etc, and want to add MX capability. If that's the case I'm wondering why you aren't using a SQL backend to BIND. It'd make scripting/automation a breeze compared to flat files. – Chris S Dec 12 '13 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.