How to make Postfix use hostnames from /etc/hosts ?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make Postfix use hostnames from /etc/hosts ?

Jaroslaw Rafa
As I have trouble with sending emails to Gmail (I wrote about it in a
different thread), I try to configure Postfix to send mail to Gmail via a
different mail server as a relay. However, for reasons too long to explain
here, I would like Postfix to refer to that server via hostname that I
defined in /etc/hosts file and not via actual DNS hostname.

My first attempt, with using the following line in the transport map:

gmail.com smtp:[aws]

where "aws" is the host name defined in /etc/hosts, resulted in failure
to send email, with the following error message from Postfix:

<......@gmail.com>: Host or domain name not found. Name service error for
    name=aws type=AAAA: Host found but no data record of requested type

I found in the documentation that I have to add the parameter
"smtp_host_lookup=native" to main.cf to make Postfix use system configured
name resolution instead of trying to resolve names by itself. So I did it,
reloaded Postfix and got the following error:

<......@gmail.com>: unable to look up host aws: No address associated with
    hostname

So I tried to change the name both in the transport map and in /etc/hosts
file from "aws" to "aws.local" to make it look more like a domain name :).
This time I got the following:

<......@gmail.com>: unable to look up host aws.local: Name or service not
    known

What am I doing wrong?
--
Regards,
   Jaroslaw Rafa
   [hidden email]
--
"In a million years, when kids go to school, they're gonna know: once there
was a Hushpuppy, and she lived with her daddy in the Bathtub."
Reply | Threaded
Open this post in threaded view
|

Re: How to make Postfix use hostnames from /etc/hosts ?

Jaroslaw Rafa
Dnia  8.10.2019 o godz. 00:09:34 Jaroslaw Rafa pisze:
> As I have trouble with sending emails to Gmail (I wrote about it in a
> different thread), I try to configure Postfix to send mail to Gmail via a
> different mail server as a relay. However, for reasons too long to explain
> here, I would like Postfix to refer to that server via hostname that I
> defined in /etc/hosts file and not via actual DNS hostname.
[...]
> What am I doing wrong?

Replying to myself, but it looks that the issue is solved - I need to
*restart* Postfix after these changes, only reloading is not enough.

(However, it didn't help with my original Gmail issue - even mail relayed
via another server still goes to spam on the receiving side :()
--
Regards,
   Jaroslaw Rafa
   [hidden email]
--
"In a million years, when kids go to school, they're gonna know: once there
was a Hushpuppy, and she lived with her daddy in the Bathtub."
Reply | Threaded
Open this post in threaded view
|

Re: How to make Postfix use hostnames from /etc/hosts ?

Rich Shepard
On Tue, 8 Oct 2019, Jaroslaw Rafa wrote:

> (However, it didn't help with my original Gmail issue - even mail relayed
> via another server still goes to spam on the receiving side :()

Jaroslaw,

While not directly related to your issue, I've found that some clients who
use gmail end up with messages I send in their spam folder. Many folks use
gmail and only a few have had this problem. I'm certain that it's an issue
with their ISP and not postfix or google (directly).

They'll call and ask why they've not received the information they requested
and I ask them to look in their spam folder. Sure enough, there sits the
original message (and attachments) I sent. That they don't think of looking
there on a daily basis, or when not receiving expected communications, is a
non-technical issue.

Glad you fixed your problem.

Rich
Reply | Threaded
Open this post in threaded view
|

Re: How to make Postfix use hostnames from /etc/hosts ?

Viktor Dukhovni
In reply to this post by Jaroslaw Rafa
> On Oct 7, 2019, at 6:09 PM, Jaroslaw Rafa <[hidden email]> wrote:
>
> I found in the documentation that I have to add the parameter
> "smtp_host_lookup=native" to main.cf to make Postfix use system configured
> name resolution instead of trying to resolve names by itself.

Unless your system sends all mail to statically configured
relays listed in /etc/hsots, you MUST NOT set:

        smtp_host_lookup = native

for all destinations.  Instead, create a second transport
in master.cf:

        nativesmtp unix ... smtp
           -o smtp_host_lookup=native

And then use "nativesmtp:[nativehost]" in the transport table
for all destinations that need to avoid DNS.

You could set:

        smtp_host_lookup = dns, native

but then all your native names will still trigger DNS lookups
first, and that's not ideal when the name is a priori known
to be native.

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: How to make Postfix use hostnames from /etc/hosts ?

Jaroslaw Rafa
Dnia  7.10.2019 o godz. 19:40:40 Viktor Dukhovni pisze:
>
> Unless your system sends all mail to statically configured
> relays listed in /etc/hsots, you MUST NOT set:
>
> smtp_host_lookup = native

But "native" doesn't mean /etc/hosts only! Native means system-configured
name resolution and this is defined by /etc/nsswitch.conf and/or
/etc/host.conf. nsswitch.conf contains the entry "hosts: files dns" and
host.conf contains "order hosts,bind". Both entries mean - try to resolve
using /etc/hosts first, and if the name is not found in /etc/hosts, resolve
using normal DNS. And this is the way it's working for me right now.
--
Regards,
   Jaroslaw Rafa
   [hidden email]
--
"In a million years, when kids go to school, they're gonna know: once there
was a Hushpuppy, and she lived with her daddy in the Bathtub."
Reply | Threaded
Open this post in threaded view
|

Re: How to make Postfix use hostnames from /etc/hosts ?

Viktor Dukhovni
> On Oct 7, 2019, at 7:46 PM, Jaroslaw Rafa <[hidden email]> wrote:
>
>> Unless your system sends all mail to statically configured
>> relays listed in /etc/hsots, you MUST NOT set:
>>
>> smtp_host_lookup = native
>
> But "native" doesn't mean /etc/hosts only! Native means system-configured
> name resolution and this is defined by /etc/nsswitch.conf and/or
> /etc/host.conf. nsswitch.conf contains the entry "hosts: files dns" and
> host.conf contains "order hosts,bind". Both entries mean - try to resolve
> using /etc/hosts first, and if the name is not found in /etc/hosts, resolve
> using normal DNS. And this is the way it's working for me right now.

Native is wrong for resolving DNS MX hostnames since, it may
try to erroneously append default domains (from the resolv.conf
search list) to fully-qualified DNS names.

While a sufficiently small "ndots" might keep you out of trouble,
"native" also breaks visibility of DNSSEC and is therefore
incompatible with DANE.

It also precludes use of the Postfix "smtp_dns_reply_filter".

It may mostly work for you, but is NOT recommended.

--
        Viktor.