Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to use one wildcard subdomain for both web and incoming email?

So, for instance:

  1. random01.example.com => handled by web server
  2. user01@random01.example.com => handled by email server

I am using Sendgrid for incoming email, and Zerigo to manage DNS.

The application is hosted on Heroku.

If it is possible, where should I look to get started?

Thanks in advance!

share|improve this question
add comment

1 Answer

Of course this is doable. The two protocols operate on different tcp ports, so when a browser is opened and pointed to random01.example.com, it's hitting your machine on port 80, and when a user emails user01@random01.example.com, it goes to whatever the MX record is in your DNS, and if that's the same machine as the webserver, it's on a different port (25).

The question of the DNS for that hostname is irrelevant. You can have random01.example.com point to your webserver IP, and mail will still work, because mail relies on the MX record in your DNS, so for all you care, you can point the MX record to a completely different domain (like google mail's service even) if you wanted to.

Say for instance your webserver is 1.1.1.1 and your mailserver is 1.1.1.5

The hostnames would be:

*.example.com IN MX mail.example.com

*.example.com IN A 1.1.1.1 (webserver)
mail.example.com     IN A 1.1.1.5 (mailserver)

And voila... people can hit random01.example.com on the web, and mail to that domain also goes to the correct mailserver.

edit: I'm using those lines as I'd probably write them in BIND. How you'd set that with your nameserver I don't know, but it should be straightforward stuff to add A records, and add an MX record that points to an existing A record. What I have found is that Zerigo accepts "*" for wildcard hostname entries in its UI.

share|improve this answer
    
The Wikipedia entry on wildcard DNS has more info on this and uses MX records as an example. –  matthew Oct 25 '11 at 16:18
    
why -1? I'm curious to know what's wrong with this answer. I currently have this sort of thing setup for multiple domains –  sandroid Oct 25 '11 at 17:59
    
@Sandroid: While you are correct, you are not at all talking about wildcard domain entries. Doing it your way would mean that a mail to user@random2.example.com would fail, and it shouldn't. –  SvW Oct 25 '11 at 18:00
    
@SvenW, point taken, I realized we were talking about wildcards but the example sucks without it - corrected –  sandroid Oct 25 '11 at 18:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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