When setting up a web/mail server on a single server or VPS with one IP address almost every guide online follows the same structure for DNS:

example.com.               IN A  
hostname.example.com.      IN A  
mail.example.com.          IN A  
example.com.               IN MX   10 mail.example.com.  IN PTR  hostname.example.com  

I used this several times and it has always worked for me. But I was wondering if there's a reason why the mail server points to a different name? Would it be possible to point the MX record to the hostname and simply use hostname.example.com for SMTP and POP3?

  • 7
    Please use for example IP addresses. (These are reserved for documentation, like example.com. See RFC5737.)
    – billpg
    Mar 14, 2012 at 11:29
  • I love SF, I learn something new every day. Thanks for that, billpg!
    – MadHatter
    Mar 14, 2012 at 11:30
  • @billpg Thanks for the tip. This was my first question so I'm still learning the ropes.
    – Jeff
    Mar 15, 2012 at 23:28

4 Answers 4


Yes, it would be possible, but you will lose some important advantages if you choose to do so:

If you point all services to the same DNS name, you can't put them onto separate servers any more without reconfiguring any client that refers to them.

As an example: With different names, when the load on the server grows too much, you can simply offload the mail services to another server without affecting the clients. All you have to do is to adapt your DNS records.

  • MX DNS records can be added at a later time, so I do no see why you loose something. Mar 14, 2012 at 0:39
  • 1
    If you tell your clients that both your web server and your IMAP/POP3 server can be reached at example.com, and you need to seperate these afterwards, how does adding an MX record later on help? Do it right from the beginning and you don't run into trouble later on because you was too lazy to add two or three more lines to your DNS zone.
    – Sven
    Mar 14, 2012 at 0:46
  • @MirceaVutcovici the point is to be able to change the underlying infrastructure without having to change all of your clients. Mar 14, 2012 at 1:13
  • @MirceaVutcovici adding or changing the MX record doesn't change where the clients look for their mail services. As I understand it MX records are only for delivery and routing, not for clients to use.
    – mp3foley
    Mar 15, 2012 at 20:44
  • I was just curious if a separate name was required or not, so it seems the answer is it isn't. But I agree it's has administrative advantages.
    – Jeff
    Mar 15, 2012 at 23:26

As per rfc5321 the mail delivery is done to the A address if MX is missing. So the following lines are not required for SMTP to work:

mail.example.com.          IN A  
example.com.               IN MX   10 mail.example.com.  

See also: http://en.wikipedia.org/wiki/MX_record#History_of_fallback_to_A

  • And in addition if the MX record exists, he can point it to hostname.example.com if he wishes.
    – hookenz
    Mar 14, 2012 at 0:42
  • You don't gain anything with this and loose a lot of flexibility, so why bother? As I said above, do it right from the beginning.
    – Sven
    Mar 14, 2012 at 0:47
  • As not everyone has redundancy for their services (think the use case of a small blogger), the same can apply to the mail server. And why you think that editing the DNS is so in-flexible? Mar 14, 2012 at 1:08
  • 1
    @MirceaVutcovici: Sorry, but what it so hard to understand about the fact that you have to change all your clients if you use the same hostname for different purposes and need to separate these services at any point in the future for any reason? Doing it your way gains yo exactly nothing and you might run into problems later on. The professional approach (and only this is at all relevant for ServerFault) is to create a reasonable DNS infrastructure that avoids stupid pitfalls like this.
    – Sven
    Mar 14, 2012 at 1:23

You can use whatever hostname that you like for your mailserver, but you do need should have an MX entry.

With that said, I do like the idea of having a separate name for different roles. First, if/when it comes time to change hosts, you're in greater control of DNS and will suffer fewer problems due to external DNS caching.

  • 3
    You don't technically need or require an MX record.
    – joeqwerty
    Mar 14, 2012 at 0:51
  • Fair enough; answer updated to reflect
    – gWaldo
    Mar 14, 2012 at 19:32

Your mail server will need a PTR record pointing to it. This will allow reverse DNS to work. I don't trust mail servers which use a second level domain like example.com as too many spammers try to claim their name is one of the big name domains. You are better off using a name like mail.example.com. If you are using mail.example.com add an MX to your main domain example.com indicating mail.example.com will receive mail. By the way neither mail.example.com nor example.com can be CNAME entries.

You can run everything on one domain name. However, if I have convinced you to use mail.example.com for you mail server, you may want to use www.example.com for your web server rather than mail.example.com. If you use www.example.com it will be easy to add parallel domain for static content which does not receive cookies from your web server.

It is common to have the IP address of the parent domain, example.com resolve to the web server's address. If you don't have a lot of web traffic you can use a CNAME record for your web domain. The rest of the services not listed above such as POP and IMAP can be handled by CNAME records. If you add different servers later you can replace the CNAME record with an A record, or simply adjust the CNAME record. Using CNAME records ease adding IPV6 as you won't need to add AAAA records to all your domains.

I like to have a DNS record for the hostname. If you do that you can use that domain instead of mail as your MX. In your example, I would drop the mail.example.com record and use hostname.example.com in your MX record. Add a CNAME record for www.example.com and you are pretty well done.

Your mail server should use whatever name the PTR record for your server uses. You may need to get your IP provider to change the PTR appropriately. Add an A record for that name as well.

Consider adding SPFs record for both hostname.example.com and example.com.

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.