How do I fake an MX record for a domain?

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?


You don't actually need to set up MX records for email delivery. 'A' records will do the job as well. See "Fallback to the address record" at Wikipedia about MX records.

In order to make fake hosts in /etc/hosts working for Postfix, you must tell it to actually use that and not just DNS-only by setting smtp_dns_support_level = disabled in /etc/postfix/main.cf. See the postconf documentation for details.

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