Automatically substitute FQDN of local system in config

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Automatically substitute FQDN of local system in config

Marat Khalili
Dear all,

I'm having trouble creating Postfix config (main.cf) without explicitly
writing domain name in it. I'd like both myhostname and mydomain
automatically set to output of `hostname -f` or contents of
/etc/mailname. However, whatever combinations of myorigin, mydomain and
myhostname I define, I either receive errors or values like
`hostname`.localdomain. Is it impossible, or am I missing some working
combination?

I'm using Postfix 3.1.0-3 under Ubuntu 16.04.


--

With Best Regards,
Marat Khalili

Reply | Threaded
Open this post in threaded view
|

Re: Automatically substitute FQDN of local system in config

Viktor Dukhovni

> On Apr 19, 2017, at 10:54 AM, Marat Khalili <[hidden email]> wrote:
>
> I'm having trouble creating Postfix config (main.cf) without explicitly
> writing domain name in it. I'd like both myhostname and mydomain
> automatically set to output of `hostname -f` or contents of /etc/mailname.

Email may persist in the queue across movements of a host (say a laptop)
between networks which may result in changes in the host's FQDN as DHCP
servers assign different domains.

It is important that bounces for a local sender are delivered to that
local sender when delivery fails some time later.

Therefore Postfix systems need a *stable* hostname, that does not
randomly change as the machine moves from place to place.

If you system does not have a stable public domain suffix, go with
"localdomain", it is far better than a time-varying suffix.

Otherwise, explicitly configure a stable public FQDN.  Do not depend
on `hostname -f`.  Postfix needs to work even when your system is off
the network, and the sender addresses of local users need to be stable.

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Automatically substitute FQDN of local system in config

Marat Khalili
Thank you for the reply. I think my question needs clarification. I'm
trying to create single configuration file that I'd be able to clone
across different servers. Manual correction of this file for every
machine is a time-consuming and error-prone step I'd like to avoid.

All servers have static IP configuration with public (within
organization) domain name, they are not moving anywhere. Therefore your
considerations do not exactly apply.

--

With Best Regards,
Marat Khalili

On 19/04/17 18:03, Viktor Dukhovni wrote:

>> On Apr 19, 2017, at 10:54 AM, Marat Khalili <[hidden email]> wrote:
>>
>> I'm having trouble creating Postfix config (main.cf) without explicitly
>> writing domain name in it. I'd like both myhostname and mydomain
>> automatically set to output of `hostname -f` or contents of /etc/mailname.
> Email may persist in the queue across movements of a host (say a laptop)
> between networks which may result in changes in the host's FQDN as DHCP
> servers assign different domains.
>
> It is important that bounces for a local sender are delivered to that
> local sender when delivery fails some time later.
>
> Therefore Postfix systems need a *stable* hostname, that does not
> randomly change as the machine moves from place to place.
>
> If you system does not have a stable public domain suffix, go with
> "localdomain", it is far better than a time-varying suffix.
>
> Otherwise, explicitly configure a stable public FQDN.  Do not depend
> on `hostname -f`.  Postfix needs to work even when your system is off
> the network, and the sender addresses of local users need to be stable.
>

Reply | Threaded
Open this post in threaded view
|

Re: Automatically substitute FQDN of local system in config

Philip Paeps
In reply to this post by Marat Khalili
On 2017-04-19 17:54:32 (+0300), Marat Khalili <[hidden email]> wrote:
>I'm having trouble creating Postfix config (main.cf) without explicitly
>writing domain name in it. I'd like both myhostname and mydomain
>automatically set to output of `hostname -f` or contents of
>/etc/mailname. However, whatever combinations of myorigin, mydomain and
>myhostname I define, I either receive errors or values like
>`hostname`.localdomain. Is it impossible, or am I missing some working
>combination?

If `gethostname()` returns a FQDN it will be used as `$myhostname`.  If
it only returns a hostname, Postfix will append `localdomain`.

>I'm using Postfix 3.1.0-3 under Ubuntu 16.04.

Linux systems often only configure their shortname with `sethostname()`
(for reasons I've never understood).  If you set a FQDN though, it will
be returned with `gethostname()`.

Try to figure out where your particular flavour of Linux sets its
hostname and teach it to set a FQDN instead of a shortname.

Philip

--
Philip Paeps
Senior Reality Engineer
Ministry of Information
Reply | Threaded
Open this post in threaded view
|

Re: Automatically substitute FQDN of local system in config

Marat Khalili
On 19/04/17 18:39, Philip Paeps wrote:
> Linux systems often only configure their shortname with
> `sethostname()` (for reasons I've never understood).  If you set a
> FQDN though, it will be returned with `gethostname()`.
>
> Try to figure out where your particular flavour of Linux sets its
> hostname and teach it to set a FQDN instead of a shortname.

You're right, this is my case! Will consider moving to FQDN in hostname
then (wonder what it may break)...

--

With Best Regards,
Marat Khalili
Reply | Threaded
Open this post in threaded view
|

Re: Automatically substitute FQDN of local system in config

Philip Paeps
On 2017-04-19 18:52:56 (+0300), Marat Khalili <[hidden email]> wrote:

>On 19/04/17 18:39, Philip Paeps wrote:
>>Linux systems often only configure their shortname with
>>`sethostname()` (for reasons I've never understood).  If you set a
>>FQDN though, it will be returned with `gethostname()`.
>>
>>Try to figure out where your particular flavour of Linux sets its
>>hostname and teach it to set a FQDN instead of a shortname.
>
>You're right, this is my case! Will consider moving to FQDN in
>hostname then (wonder what it may break)...

For what it's worth, I've never encountered anything that *relies* on
the weird Linux behaviour.  [But plenty of things that don't work around
it as elegantly as Postfix does by appending .localdomain!]

Philip

--
Philip Paeps
Senior Reality Engineer
Ministry of Information
Reply | Threaded
Open this post in threaded view
|

Re: Automatically substitute FQDN of local system in config

Marat Khalili
On 19/04/17 19:00, Philip Paeps wrote:
> For what it's worth, I've never encountered anything that *relies* on
> the weird Linux behaviour.
Well, my .bashrc ... :)

> [But plenty of things that don't work around it as elegantly as
> Postfix does by appending .localdomain!]
I don't want to complain right away, but the proper fix would be to
obtain actual FQDN regardless of system default for hostname.

Also, Debian-derived distributions including Ubuntu seem to support
taking myorigin from /etc/mailname, but don't go the full way in
supporting it for all parameters. Weird indeed.

--

With Best Regards,
Marat Khalili

Reply | Threaded
Open this post in threaded view
|

Re: Automatically substitute FQDN of local system in config (THREAD CLOSED)

Viktor Dukhovni

> On Apr 19, 2017, at 12:16 PM, Marat Khalili <[hidden email]> wrote:
>
> I don't want to complain right away, but the proper fix would be
> to obtain actual FQDN regardless of system default for hostname.

There's no magic, the FQDN has to come from some stable source.
As already explained, DNS resolution is not such a source.

If all the hosts in question have a common domain, you can get
an FQDN for "myhostname" by setting "mydomain", which will then
be appended to the short hostname.

So you can include the domain in the hostname of the system, or
you can tell Postfix what domain to append by setting "mydomain".

Your choice.  We should stop here.  Nothing new and useful is
likely to be said in this thread beyond this point.

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Automatically substitute FQDN of local system in config (THREAD CLOSED)

Wietse Venema
Viktor Dukhovni:

>
> > On Apr 19, 2017, at 12:16 PM, Marat Khalili <[hidden email]> wrote:
> >
> > I don't want to complain right away, but the proper fix would be
> > to obtain actual FQDN regardless of system default for hostname.
>
> There's no magic, the FQDN has to come from some stable source.
> As already explained, DNS resolution is not such a source.
>
> If all the hosts in question have a common domain, you can get
> an FQDN for "myhostname" by setting "mydomain", which will then
> be appended to the short hostname.
>
> So you can include the domain in the hostname of the system, or
> you can tell Postfix what domain to append by setting "mydomain".
>
> Your choice.  We should stop here.  Nothing new and useful is
> likely to be said in this thread beyond this point.

Perhaps one note: the criticial setting is myorigin as that determines
the default return address of email that is sent out.

The other names, myhostname and mydomain, should not matter if you
send all outbound email through a stable relay host (this will
usually require some form of authentication; you can use SASL over
TLS (see http://www.postfix.org/SASL_README.html), use a VPN, or
SSH port forwarding.)

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: Automatically substitute FQDN of local system in config (THREAD CLOSED)

Marat Khalili
Thank you guys for explanations and workarounds. Sorry if I hurt someone's feelings: postfix is already great and so on. I received answer on my question and will fill in myhostname with sed for now.
--

With Best Regards,
Marat Khalili