Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm testing two mail servers that live on two (virtual) machines with made up domain names for emails. When one of the servers needs to send an email to the other one, it seemingly performs a DNS lookup for the recipient domain's MX record, which doesn't point the sender server to the correct IP, no matter what IP/domain mapping I put in /etc/hosts.

So should I install a DNS server and create a custom MX record for the recipient domain? How do I do this on Ubuntu 12.04 or is there an easier way?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Opposed to what a lot of people think, you don't actually need to set up MX records for email delivery. 'A' records will do the job as well. See "History of fallback to A" at Wikipedia about MX records.

Alternatively, you could configure your MTA (e.g. Postfix) to use a specific transport for a domain. For Postfix use transport_maps.

In order to make faking hosts in /etc/hosts working for Postfix, you must tell it to actually use that and not just DNS-only. See the postconf documentation on how to do that. Hints: smtp_host_lookup or disable_dns_lookups.

share|improve this answer
    
I tried to make it fallback by blocking the DNS port 53 which worked only partially: instead of resolving to an incorrect recipient IP using an MX record of some internet DNS server that is unknown to me, it now doesn't resolve at all: status=deferred (Host or domain name not found. Name service error for name=example.com type=MX: Host not found, try again). Sure example.com is set to the correct IP in etc/hosts. –  Desmond Hume Nov 20 '12 at 13:10
    
@DesmondHume I've updated my answer for Postfix to use the native host lookup on your system. –  gertvdijk Nov 20 '12 at 13:24
1  
Adding disable_dns_lookups = yes to /etc/postfix/main.cf did the job (smtp_host_lookup = native did not). Thanks a bunch. –  Desmond Hume Nov 20 '12 at 13:49
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.