How do I fake an MX record for a domain?

26,814

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.

Share:
26,814

Related videos on Youtube

Desmond Hume
Author by

Desmond Hume

Updated on September 18, 2022

Comments

  • Desmond Hume
    Desmond Hume over 1 year

    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?

  • Desmond Hume
    Desmond Hume over 11 years
    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.
  • gertvdijk
    gertvdijk over 11 years
    @DesmondHume I've updated my answer for Postfix to use the native host lookup on your system.
  • Desmond Hume
    Desmond Hume over 11 years
    Adding disable_dns_lookups = yes to /etc/postfix/main.cf did the job (smtp_host_lookup = native did not). Thanks a bunch.