Wednesday, July 29, 2009

Postfix: Name service error resolving localhost

I thought I'd share this bit of information for those of you that use Postfix. If you want to forward your email to a smarthost that requires authentication over an ssl tunnel you've no doubt come across many guides on the net. They'll all tell you to place some variation of
"relayhost=localhost:###" in your main.cf config file along with the necessary entries for authentication in the sasl_passwd database and use stunnel in client mode.

Unfortunately, it seems that the version of Postfix included on my Ubuntu 9.04 system has issues with that configuration. In fact, my mail.info logs were spammed with the following messages:

postfix/smtp: warning: relayhost configuration problem
postfix/error: [irrelevant stuff snipped] Name service error for name=localhost type=A

Even though I have a valid entry for localhost in my /etc/hosts file it seems that the name resolution request was escaping to my isp's dns servers which have no idea what localhost should resolve to and rightfully return an error.

To fix this, try one of the following variations:

relayhost=[localhost]:###
relayhost=[127.0.0.1]:###

Documentation here:
http://www.postfix.org/postconf.5.html#relayhost

I wish there had been a clear, concise post on what the solution to this problem was. I spent way too much time reading dead end posts on mailing lists before everything clicked into place. Hopefully, this will save someone else some time.

2 comments:

Unknown said...

Never had this problem before, even after upgrading to Ubuntu 12.04.

But today, I am at a hotel where the wifi network configuration seems to be pretty bizarre. The DHCP server says the DNS is 127.0.0.1, and once the negotiation is over, the route to that address is no longer over the loopback interface, but rather the default route!

I all kind of works, except I couldn't send emails, anymore, with the very same error that you got. Googling it, I found your post, and it was very helpful. So, a big, huge, THANK YOU!

alyandon said...

Yep, it's one of the reasons I leave these ancient posts up. Glad to see it helped point someone in the right direction!