How do I change Exim4's primary_hostname on a Debian box?
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.
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.
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.
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.)
after adding the the same string in /etc/hosts, hostname -f will return your FQDN