1 (edited by paco 2014-05-03 19:50:40)

Topic: Purpose of listing FQDN first in /etc/hosts?

==== Required information ====
- iRedMail version: 0.8.6
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Linux/BSD distribution name and version: CentOS 6.5 (OpenVZ VPS container)
- Related log if you're reporting an issue:
====

Something isn't clear to me at the "Set a fully qualified domain name (FQDN) hostname on your server" section in http://www.iredmail.org/install_iredmail_on_rhel.html.

I am installing iRedMail on a VPS at home. (This means, my physical machine runs CentOS, and it has several virtual machines also running CentOS, using OpenVZ. One of these virtual systems is the system we're going to talk about here.)

The documentation says about /etc/hosts: "Warning: List the FQDN hostname as first item." When I do that like in the documentation's example ("127.0.0.1 mail.XX.XX mail localhost, etc.) and reboot, OpenVZ restores the /etc/hosts file to the one OpenVZ prefers in which the FQDN is not listed as first item. There must be a reason for OpenVZ doing this, like ensuring that a virtual system runs correctly. This is the /etc/hosts file OpenVZ likes me to use:

[root@mail ~]# cat /etc/hosts
127.0.0.1 localhost.localdomain localhost localhost4.localdomain4 localhost4
# Auto-generated hostname. Please do not remove this comment.
192.168.XX.XX mail.XX.XX  mail
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

(I masked IP address and FQDN for privacy/security/whatever.)

The choice to be made is between these two options:
A.) Leave /etc/hosts as it is, and thus obeying OpenVZ's preference and neglecting iRedMail's warning.
B.) Obey iRedMail's warning and automatically restore a corrected /etc/hosts file at every boot, having the FQDN listed first. This can be done by adding a few lines to the /etc/rc.d/rc.local script.

Both options result in a correct FQDN when issuing "hostname -f". Option B results in mentioning something in the nightly log analysis like "/etc/hosts and iRedMail's hosts file are different".

My question is, what is the purpose of having the FQDN listed first? And what are the consequences if I don't?

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Purpose of listing FQDN first in /etc/hosts?

if you don't list the FQDN hostname as first itme, some Linux/BSD distributions won't return FQDN hostname with command 'hostname -f'. That's why we ask users to do this before installing iRedMail. So, if 'hostname -f' returns correct FQDN hostname on your server, order doesn't matter at all.

iRedMail needs a FQDN hostname to set in some config files, e.g. Postfix parameter "myhostname".

3

Re: Purpose of listing FQDN first in /etc/hosts?

Thanks for your quick response! It is clear to me now.

4

Re: Purpose of listing FQDN first in /etc/hosts?

Hi Paco.. I am running into the exact problem with OpenVZ rewriting my hosts file. What did you add to the local script to fix it on boot?

Thanks!
Chris

5

Re: Purpose of listing FQDN first in /etc/hosts?

Hi Chris. I added the following lines to /etc/rc.d/rc.local:

cat > /etc/hosts << "EOF"
127.0.0.1 mail.example.com mail localhost.localdomain localhost localhost4.localdomain4 localhost4
# Auto-generated hostname. Please do not remove this comment.
192.168.XXX.XXX mail.example.com  mail
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
EOF

(You should replace any instance of mail.example.com and mail by your mailserver's full and short name. You should also replace 192.168.XXX.XXX by your mailserver's IP-address.)

Mind that this solution works for a Centos 6.5 OpenVZ host where iRedMail is being installed on a Centos 6.5 OpenVZ container. I found out that this configuration doesn't need this adjustment. At least at my system it doesn't. Other configurations possibly need this or other adjustments.

Also, my solution is the first that came to mind. It may be easier to create a ready-made hosts file somewhere on your system and ask the script to copy it, like this:

cp -f /root/hosts-for-iredmail /etc/hosts

This second method is easier, but I personally do not prefer it because it needs adjusting/creating two files instead of one. smile

Good luck! wink

6

Re: Purpose of listing FQDN first in /etc/hosts?

Thanks Paco! While waiting for your reply, I ended up trying something I found on an OpenVZ forum that seemed to work:

"Delete the "HOSTNAME= domain.com" entry from the specific VZ container config file (e.g. 101.conf) and it doesn't overwrite it at boot anymore."

For what I am doing, this seems to work fine - multiple reboots and the hosts files don't change. However, I will keep your method handy in case I run into trouble.

Take care.