27

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 :(

8 Answers 8

23

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.

5
  • I have changed /etc/hostname from a local machine name to the FQDN. hostname -f still reports "localhost". The part about /etc/hosts in your answer seems buggy - what is the first record supposed to look like? Jul 27, 2009 at 16:08
  • 1
    While hostname -f still reports "localhost", it seems that the change to /etc/hostname did the trick - I am able to deliver my mail now. I still would like to see the missing part of your post though :) Jul 27, 2009 at 16:15
  • Oops! Formatting flub. Fixed :-) Jul 27, 2009 at 16:37
  • 1
    /etc/hostname doesn't typically contain the FQDN on Debian systems, only the short hostname. Dec 18, 2017 at 20:08
  • Well, the first line in /etc/hosts might be 127.0.0.2 mydomain.com myhostname (127.0.0.2 works as well as 127.0.0.1, since loopback is a class A network). You can probably combine the two lines into one 127.0.0.1 mydomain.com myhostname localhost, but localhost is a canonical hostname for 127.0.0.1, isn't it? That all given that you have hostname, not FQDN as your hostname. Also, changing /etc/hostname doesn't take effect immediately, you've got to hostname myhostname. Or restart server.
    – x-yuri
    May 2, 2019 at 5:33
10

If you use a single configuration file, set the PRIMARY_HOST_NAME variable to the desired name:

For example in /etc/exim4/exim4.conf:

PRIMARY_HOST_NAME = mybox.mydomain.com

or set MAIN_HARDCODE_PRIMARY_HOSTNAME in update-exim4.conf.conf if you are using split file configuration.

To be safe, restart exim.

5
  • Just a note that the host listed can't be in quotes, otherwise exim sends HELO 'mybox.mydomain.com' which breaks sending mail to Google, perhaps others. Jul 27, 2016 at 15:32
  • 1
    I can't find any mention of this "PRIMARY_HOST_NAME" variable name in the documentation. Where did you find this? Dec 18, 2017 at 20:23
  • On Debian you've got to run update-exim4.conf after changing config. And restart is generally not needed after that.
    – x-yuri
    Apr 28, 2019 at 17:43
  • ...Well, exim generally seems to notice the changes to the config without reload. But it's arguably safer to reload, since I suppose the daemon itself doesn't reread the config until reload. Then, you make it sound like /etc/exim4/exim4.conf can contain just the line above, but the moment you create the file, /var/lib/exim4/config.autogenerated gets ignored...
    – x-yuri
    May 2, 2019 at 6:00
  • ..."The forked processes Exim starts for SMTP receiving or queue running would use the new configuration file, while the original main exim-daemon would still use the old configuration file." So, for single configuration file it's best to use /etc/exim4/exim4.conf.localmacros, for split /etc/exim4/conf.d/main/000_localmacros (files in main dir are processed first). And run update-exim4.conf + systemctl reload exim4 after making changes.
    – x-yuri
    May 2, 2019 at 6:01
5

The primary hostname is prompted for during the installation of exim4. You can run the command

sudo dpkg-reconfigure exim4-config

to go through the prompts again.

As far as I know, if you're already using the 'split configuration' (lots of little files under /etc/exim4/conf.d) and opt to stick with that when prompted, dpkg-reconfigure shouldn't overwrite any of your existing config alterations other than to the settings it prompts you for, but, as ever, you should take a backup first to be safe.

2
  • 2
    It only seems to ask for a "mail name [which] should be the single, fully qualified domain name (FQDN)". However, this setting is correct already, and the HELO still seems to say "localhost". Jul 27, 2009 at 16:06
  • What you're talking about is a mail name that goes to, surprise, surprise, /etc/mailname. By default it's used to qualify unqualified addresses. The ones that consist only from username. By adding domain name from /etc/mailname. The resulting address is used in the From header.
    – x-yuri
    May 1, 2019 at 18:09
4

The primary_hostname variable is filled according to the fully qualified domain name (FQDN) of the system. On Debian and related systems this is typically formed using the contents of the /etc/hostname and /etc/hosts files. The hostname file should contain the short hostname (e.g. foo), and the hosts file should contain an entry resolving foo into foo.bar.baz, i.e. hostname with its domain suffix (normally matching a DNS entry).

The output from the command hostname (without any parameters) will return the former, and the hostname -f output will return the latter.

The hostname file is typically filled upon installation, and the hosts file can be edited to have one other record in it beside the default localhost records - it should be of the form:

<IP address> <hostname FQDN> <hostname>

The three columns should be separated by spaces or tabs, it doesn't matter. The IP address can be 127.0.0.1 just like localhost, but the hostname part has match the system hostname, and the middle part should be the FQDN, i.e. hostname with a domain suffix.

To verify the line is working, simply run hostname -f and check that it returns your server's FQDN.

Finally, restart Exim, e.g. with:

sudo service exim4 restart

Afterwards you should start seeing it HELO properly. Its variable can be verified by running:

/usr/sbin/exim4 -bP primary_hostname

(NB: I originally did this as an edit to the answer from 2009, but it was rejected. The things I was originally fixing are: there was no need to repeat the default localhost record, just explain what the addition should be; explain which IP address can be used; explain what is FQDN; explain how to verify exim itself.)

8
  • /usr/sbin/exim4 -bP primary_hostname doesn't work. You can verify HELO hostname by sending a test email to either port25's authentication checker, or any other mailbox where you can see the original. More on it here. Consider updating your answer.
    – x-yuri
    May 2, 2019 at 6:08
  • It works just fine on my Debian stable machine (stretch). Can you please explain exactly it doesn't work for you? Note the documentation at exim.org/exim-html-current/doc/html/spec_html/… clearly says that the default helo_data is $primary_hostname. On Debian systems, you can override it using the REMOTE_SMTP_HELO_DATA variable, but if you just set your primary hostname properly, that's not necessary. May 2, 2019 at 14:33
  • I believe I tried and it complained about not taking an argument. But can't reproduce it now, so never mind, my bad. Regarding "if you just set your primary hostname properly," it's not generally accepted that hostname must resolve to anything. So let's say "if you set hostname the way exim expects you to..." and leave it at that :)
    – x-yuri
    May 2, 2019 at 17:54
  • I'm sorry, but I don't think it's wise to take any ad hoc conclusion of a long debian-devel discussion from over a decade ago at face value. It would be more helpful if you pointed to some policy document regarding such a thing. May 2, 2019 at 19:50
  • That's the best I could find. If you can find anything better or a proof of your words, I'd be glad if you tell me. For now all I can say is that even these days there are people who don't put hostname to /etc/hosts. And all I ask is to not call proper what is not generally accepted.
    – x-yuri
    May 2, 2019 at 22:35
1

after adding the the same string in /etc/hosts, hostname -f will return your FQDN

1
  • In other words, myhostname goes to /etc/hostname (followed by hostname myhostname). And 127.0.0.1 mydomain.com myhostname.com localhost goes to /etc/hosts. Plus reload exim just in case.
    – x-yuri
    May 1, 2019 at 18:14
0

I have the same problem. I need to change the mail hostname, because some emails fails, when them was sended. Whith this error:

host receiver.server.com [200.200.200.200]: 550 <[email protected]>: Sender address rejected: Domain not found

So I change it into the /etc/exim.config the param primary_hostname

Some code of this file:

smtp_connect_backlog = 50
smtp_accept_max = 100

#primary_hostname = myhostname.com 
deliver_queue_load_max = 3
1
  • Hah, this post helps me with "primary_hostname" and now my exim works better than ever :)
    – user184004
    Nov 6, 2014 at 9:35
0

in WHM goto Exim Configuration Manager -> Advanced Editor

scroll down until you find "Add additional configuration settings" (a big blue button) and click it.

in the new line, add [ primary_hostname ] = [ mydomain.com ]

scroll to the bottom and click Save.

0

I've spent some time to figure all required steps to change hostname so this answer is to summarize everything for Debian 9 in one place:

To change hostname you need to run:

hostnamectl set-hostname example.com

Note: use your domain FQN as hostname. If you use something else - you will get mail delivery rejections like "Helo command rejected: need fully-qualified hostname".

Finally: edit /etc/hosts so that it looks like:

127.0.0.1   localhost
xxx.xxx.xxx.xxx   example.com

xxx.xxx.xxx.xxx is IP of your server.

Then verify changes by running

hostname

It must return example.com.

Then run

hostname -f

It must return your domain FQN like example.com

Also verify that /etc/hostname contains example.com and change it if not so that hostname persists after OS restart.

OS part done. Let's continue to exim.

To be sure exim uses new hostname you need to edit /etc/exim4/exim4.conf.localmacros and add line:

primary_hostname = example.com

Note: exim config editing is optional and if /usr/sbin/exim4 -bP primary_hostname returns your new hostname - editing /etc/exim4/exim4.conf.localmacros is not required.

But you still must update exim configs and restart exim:

update-exim4.conf
service exim4 restart

And finally verify exim hostname by running

/usr/sbin/exim4 -bP primary_hostname

It must return example.com

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .