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 set up a default MX record for subdomains ?

Example:

domain example.com
MX record set for example.com to mail.example.com
MX record for sub2.example.com to mail2.example.com

Is there a way I can make sure that mails sent to user@sub2.example.com would be sent to user@example.com without having to define a MX record for the sub2 subdomain ?

Kind regards,

share|improve this question

migrated from superuser.com Dec 8 '10 at 20:18

This question came from our site for computer enthusiasts and power users.

add comment

4 Answers

up vote 4 down vote accepted

Note that e-mail forwarding doesn't happen via DNS records, it happens in the mail server. Based on my testing, you are going to need to create an MX record in the sub-domain when you you create that zone, assuming that you have other zone information. A wild-card MX record in the parent zone will be hidden by the zone. But maybe you are ok with this, if you don't need any records other than MX in the sub-zones.

As I said, that MX record isn't going to cause mail servers to cause e-mail to user@sub2.example.com to be rewritten to go to user@example.com, it will just cause the e-mail for user@sub2.example.com to go to the mail server that you specify in the MX record.

The mail server will also need to be configured to handle mail for sub2.example.com. In postfix, to make this happen automatically, it will depend somewhat on what your exact configuration is for e-mail delivery (if you are using local system accounts, or the virtual delivery agent, or a transport), but in general regex maps will be able to help. For example you could use a regex map as your virtual_maps or local_recipient_maps and then list a record like:

/^(.+)@.+\.example\.com$/    $1@example.com

You will also need to set up the domains as Postfix virtual domains, though via regex maps you will probably be able to make this configuration static (not requiring updates for every new sub-domain you create).

share|improve this answer
    
Thank you, that helps me a lot. –  Veynom Dec 7 '10 at 14:01
    
So if I don't have admin access to the mail server (i.e. mail sever for foo@example.com.. very typical for shared hosting setup), does that means foo@bar.example.com will be impossible to forward to foo@example.com? –  Antony Mar 7 '12 at 4:04
add comment

There is no one answer fits all, and you will probably get a better answer on ServerFault (Voting to move).

This really depends on the DNS server that you are using. If it allows wildcard queries, you can try setting a MX record for *.domain.com inside the domain.com object... Do not create an actual domain object for the subdomain.

However, the downside to this is all queries - sub2 or subx will all result in the same record being done.

As for the second part of your question, this comes down to the mail server, typically having forwarders is easy (once MX records are set up and resolves), but you usually need to manually set them up.

share|improve this answer
    
In my testing, creating an MX record for *.example.com causes it to also respond with A records for names, and if I add an A record for a name, the MX record gets hidden by this name. –  Sean Reifschneider Dec 7 '10 at 13:44
    
@Sean Reifschneider, as I said, different DNS servers will behave differently. –  William Hilsum Dec 7 '10 at 16:38
    
@Wil: Yeah, that could be... I tested on a recent BIND. –  Sean Reifschneider Dec 7 '10 at 19:33
add comment

Yes you can have separate MX records for a subdomain so that mail for subdomain address such as user@sub2.example.com is handles by a different mail server than the main domain.

As has been said you can't forward mail with an MX record that is done by the mail server. You could either use mail forwarding or have mail both addresses delivered to the same mailbox.

You won't get any mail to the subdomain without an MX records for it, although most control panels will add a default record when you create the subdomain.

share|improve this answer
add comment

On Godaddy, I can do this.

For example, set in domain.com's DNS Manager. Add MX (Mail Exchanger) record:

Priority: 0 Host: email Points to: email server

share|improve this answer
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.