0

Environment: CentOS, Postfix, Dovecot, Digital Ocean droplet

My /etc/hosts file contains these lines.

# The following lines are desirable for IPv4 capable hosts
127.0.0.1 example.com example
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4

# The following lines are desirable for IPv6 capable hosts
::1 example.com example
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

Question: After I install a Postfix mail server do I need to add mail.example.com to the first line in the IPv4 and IPv6 sections? If I do does it matter what order the hosts are listed in?

For example,

127.0.0.1 example.com example mail.example.com

Addendum: These comments are at the top of the hosts file. Not sure if they mean anything in this instance because when I edit this file the changes appear to persist.

# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.redhat.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
myNewAccount
  • 569
  • 1
  • 6
  • 19

1 Answers1

1

It's unclear what specific problem you're trying to avoid or fix, so some general tips:

The server needs to know its hostname. I typically set that in the main.cf:

myhostname = mailserver.mycompany.net
myorigin = @myhostname

The following is something I do when the domain has strict DMARC that doesn't allow the use of subdomains:

masquerade_domains = $mydomain
masquerade_classes = envelope_sender, header_sender

This will make the origin mycompany.net. It's beyond the scope of this answer to understand why; the internet has many sources.

Then, the following needs to be correct:

  • The mailserver will connect to other servers using SMTP saying HELO mailserver.mycompany.net.
  • Many of those 'other servers' will then resolve the IP of that, and lookup the PTR record (reverse DNS) of that IP and that must match. PTR records are typically configured at your hosting provider.

This applies to both IPv4 and IPv6.

As for editing /etc/hosts: cloud-init may not overwrite files on every boot, but it may very well do so in the future. If editing the hosts file is required, you may want to configure cloud-init to preserve it.

The order shouldn't matter, but you can test it. Make up some names with an IP address, and do host on them.

Whether you need to set it? Depends on the DNS environment. I often do set the fqdn entry of the server in /etc/hosts like:

22.33.44.55 mailserver.mycompany.net mailserver

This way, hostname --fqdn works, despite of the DNS config. Having hostname --fqdn work is recommended, but with the above configuration of Postfix, not necessary, because it's specified. (but other services may behave unexpectedly).

Halfgaar
  • 8,084
  • 6
  • 45
  • 86