Try setting the second line in hosts to
188.8.131.52 mail.domain1.com mail. Also, rebooting is not necessary: the FQDN isn't stored anywhere, it's looked up on-the-fly.
I believe that the FQDN is found by doing a DNS query on the server's IP address, then taking the first response, which is why this works. It should be possible to set the FQDN without modifying hosts by using only DNS (or NIS, or LDAP, or wherever else
nsswitch.conf looks for hosts) but if it's in the hosts file there's no need for network traffic that might time out or otherwise cause problems in an emergency.
Here's everything that happens (this is Linux-only, other OSes may and will do things somewhat differently):
hostname uses the
gethostname(2) function specified in
unistd.h to obtain the hostname. This function is implemented as a call to
uname(2), where the
nodename field of the structure is extracted and returned. This will have been set earlier in the boot process with the corresponding
sethostname(2) call, since the kernel has no other way of knowing the host's name. In your case, it will be
mail. (By the way, this is what you should have in
This is then resolved using the standard system resolver, which will be either
gethostbyname(3) depending upon the vintage of your system utils. The field
h_name, defined as "official name of host", gets returned. I believe this corresponds to the first name listed in a hosts file.
As for your multiple domains question,
hostname is not able to deal properly with multiple names. Every interface (even virtual ones) can have its own IP and sometimes even multiple physical interfaces can share an IP.
You should ensure that each IP attached to your host resolves via reverse-IP lookups to the appropriate name and configure your mail server properly.