Score:0

can I have A record and MX record for the same hostname?

eg flag

Can I have an A record and a MX record for the same hostname?

For example

example.com  A   192.0.2.42
example.com  MX  mail.anothersite.example.

Context

I'm trying to conciliate a gmail email forward (GMail requires for that MX records with hostnames without mail.*) with a website hosted at the 192.0.2.42

Example of typical gmail email forward configuration: enter image description here

Nikita Kipriyanov avatar
za flag
Yes, this is normal and widely used configuration. It means you have your mail exchanger is not the same as your web server. What problem do you have with that?
eg flag
@NikitaKipriyanov all the examples I see around have an MX record with host equal to `mail.example.com`, that is, always a subdomain `mail.`. I thought it was some kind of mandatory to be a subdomain
Score:2
za flag

This is supported and actually widely used configuration. Almost everybody uses it.

Don't confuse "mail.example.com" with MX record for "example.com". Those are completely different things. "mail" is just a name. You can use it for anything. There are absolutely no rules how it should be used and that it must be used at all. It plays zero significance in email delivery. On the contrary, MX DNS record is the definitive source of information for other mail systems, which tell them how to delivery mail for this domain. An MX host can have name "blah" and have a record blah.example.net A some.ip.add.ress and for "example.com" mail to be delivered there, you just add corresponding MX record, like example.com. MX 10 blah.example.net. and live happily. At the same time, you can also have a name "mail" only for web mail access. This is only reception side; originating mail is controlled other way.

By the way, notice a number in the MX record, a "priority". The mail delivery first tried according to the record with lowest "priority", then if that host doesn't answer, to the next lowest and so on.

It seems some systems use "mail" name for their MX host name, mostly smaller ones. This is fine. On small sites a single system often does everything and it is convenient to give it name "mail". Large sites often have some hosts that receive mail, other hosts which originate it, third ones which do web mail access, some more which process IMAP, and others can accept user submissions. There is no concrete system which could be called just "mail", so often they don't use this name at all.

A note about "apex A" record, example.com. A ip.ad.dr.ess. If a domain don't have MX record at all (i.e. if there are no records like example.com. MX priority mx.host.name.), other mail exchangers will fall back to delivery the mail for this domain to the "apex" record (and they will connect to the ip.ad.dr.ess for that). MX record exists in the world precisely to deflect mail from this system to some dedicated mail server. Of course, when you have MX, you can use "apex" record for anything, including a web side, or not use it at all.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.