Sign up ×
Server Fault is a question and answer site for 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. => handled by web server
  2. => 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

1 Answer 1

Of course this is doable. The two protocols operate on different tcp ports, so when a browser is opened and pointed to, it's hitting your machine on port 80, and when a user emails, 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 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 and your mailserver is

The hostnames would be:


* IN A (webserver)     IN A (mailserver)

And voila... people can hit 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 would fail, and it shouldn't. –  Sven 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

Your Answer


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.