i'm running a DNS-server for example.com
, with multiple A/CNAME records pointing to different IP-addresses.
@ IN A 198.51.100.1
a IN A 198.51.100.3
b IN CNAME a
c IN A 203.0.113.12
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 203.0.113.25
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 198.51.100.3
* 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
?
summary
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 198.51.100.1
@ IN MX 10 mail
a IN A 198.51.100.3
a IN MX 10 mail
b IN CNAME a
b IN MX 10 mail
c IN A 203.0.113.12
c IN MX 10 mail
mail IN A 203.0.113.25