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 [email protected] would be sent to [email protected] without having to define a MX record for the sub2 subdomain ?
Kind regards,
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
[email protected]
to be rewritten to go to[email protected]
, it will just cause the e-mail for[email protected]
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 yourvirtual_maps
orlocal_recipient_maps
and then list a record like: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).
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 thedomain.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.
Yes you can have separate MX records for a subdomain so that mail for subdomain address such as [email protected] 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.
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