Postfix resolving /etc/hosts entries

Most of times when you are setting up a mail server you need to test that all is going fine. Well, in fact tests should happen *after* the server is configured. Talking about an integral email solution (send + receive), some kind of tests come to my mind:

  • Auth tests vía smtp/pop/imap
  • Send an email to a local existent/inexistent user
  • Send an email to a remote existent/inexistent user
  • Carefully test main internet email providers (gmail, yahoo and hotmail)
  • Receive an email from a local account
  • Receive an email from a remote account
  • Check filters and other custom stuff

Nothing so complicate... unless your server is not a DNS MX endpoint. I mean if the server is not in "production" state (because we're configuring it) there shouldn't be any entry pointing to it, so how could we test the incoming email?.

We need to tweak other mail server (the one from which we're going to send the test email) to say: "hey friend, the email you're going to send is not for the real MX entry in DNS for example.com, please deliver it to this other IP". Thanks Wu for the idea. May you think how? of course, /etc/hosts:

12.12.12.12    mail.example.com

But, if the email server you're tweaking is Postfix you'll have to change a bit the configuration, because it's not taking care of /etc/hosts by default, you need to change a couple of directives (lmtp_host_lookup, smtp_host_lookup) to say: "hey friend, take in account /etc/hosts before to go to dns stuff". Here we go, in main.cf:

lmtp_host_lookup = native
smtp_host_lookup = native

Now restart the postfix and write an email (echo "testing" | main account@example.com) while tailing logs to ensure all is happening in a right way.

sysadmin

About the author

Óscar
has doubledaddy super powers, father of Hugo and Nico, husband of Marta, *nix user, Djangonaut and open source passionate.