How to Change Exim4’s Primary Hostname on Debian

debianeximhostname

Some remote SMTP server I am trying to deliver mail to refuses to accept the HELO from my server:

504 5.5.2 <localhost>: Helo command rejected: need fully-qualified hostname

Apparently, my Exim4 server sends localhost as its FQDN. Searching the net and a bunch of config files, I have learned that the value sent as FQDN during HELO is drawn from the primary_hostname configuration variable.

My question is: what is the correct way to change this variable in a Debian system? I guess I can simply hardcode a value in on of the Exim4 config files, but IMHO it would seem to make more sense if the value automagically corresponded to /etc/mailname or some other centralized name config.

I have a feeling that the answer to my question can be found in this text from the Debian wiki:

The name used by Exim in EHLO/HELO is pulled from configuration option primary_hostname. Debian's exim4 default configuration does not set primary_hostname. Exim then defaults to uname() to find the host name. If that call only returns one component, gethostbyname() or getipnodebyname() is used to obtain the fully qualified host name.

If your Exim HELOs as localhost.localdomain, then you have most probably a misconfigured /etc/hosts created by some versions of the Debian installer. In this case, please fix your /etc/hosts.

Unfortunately, I am not familiar enough with Linux server administration to know exacly what all this means 🙁

Best Answer

Your /etc/hosts file should have at least two records in it. The first record should be of the form:

<IP_ADDRESS> <HOST_FQDN> <HOSTNAME>

the second one should be of the form:

127.0.0.1 localhost

You also need to make sure that your /etc/hostname file contains the server's FQDN, and that running hostname -f returns your servers FQDN. If you make sure all of this is correct, and restart Exim, you should start seeing it HELO properly.