Naming issues with Linux and xBSD

Incorrect hostnames on Linux (and occasionally with xBSD, such as FreeBSD, NetBSD, OpenBSD etc) often lead to problems both with the CBL, and with hosted spam filters that insist on RFC821/RFC2821/RFC5321 compliance.

This will most frequently appear with sendmail systems that are uttering a helo of "localhost.localdomain" or single-token hostnames like "mail", and the headers in sent email will be inappropriately sprinkled with it. Up to and including From lines that have localhost.localdomain instead of your real domain. Clearly that's not working properly.

There can be similar issues with Exim, Postfix, Sendmail and Qmail or any other Linux/xBSD email system.

It all has a common cause: the machine's name is not set right.

Most of this is due to poor understanding of and idiosyncracies in install or configuration change procedures. It confuses the experts because every flavour of UNIX is different, but hopefully, this page will assist with machines intended to be used as mail servers.

This page attempts to describe how to make sure that everything is right.

In this page, "" is used as your domain, "" is used as the hostname you want your machine to be, and is your static IP (assuming that you have one).

WARNING: This page is specifically intended to assist in getting Linux/xBSD mail servers to know their own name properly. Situations where you'd not normally want to run a mail server (eg: the machine is on dynamic IP addresses or WIFI strangeness) are not covered. The link below can be consulted for more advanced situations.

The instructions for changing the host name vary between versions of FreeBSD and Linux. The best thing to do is first check out whether they're already right. If they're right, in which case you need to go no further.

A bit of terminology first, let's say your fully qualified name (name for this specific machine) should be "".

  1. The fully qualified domain name (FQDN) is "".
  2. The domain name is "".
  3. The hostname (or "short name") is "mail".

Caution: some documents refer to the FQDN as the "hostname", and systems vary whether they return the FQDN or "short name" as the result of the "hostname" command.

The following is a sequence of Ubuntu (all Debian-derived machines should be the same) commands you should execute, and their expected results (substituting etc with the values you want for your machine):
shell prompt>  hostname -s

shell prompt>  hostname -d

shell prompt>  hostname -f

Another thing to quickly check is the /etc/hosts file. The /etc/hosts file will generally look something like this (using "" as the name of the machine, and as its IP address): localhost mail

If your machine does IPv6 too, you should see another pair of lines like this, where "<ipv6 address>" is the IPv6 address for your machine:

::1	localhost localhost.localdomain
<ipv6 address> mail

The "localhost" definitions must be in front of the real IP addresses, and in no case should the localhost entries include "mail" or "".

If the results you obtain from the above commands is what you're expecting, breath a sigh of relief, you're done with this page

Seeing localhost or localhost.localdomain or a name without dots (except where we explicitly say they should be) are clear signs of wrongness.

If the results are wrong, there's a number of things you may need to change, depending on what version of Linux/FreeBSD you are running. We recommend doing a web search for "setting hostname " (where is replaced with the Linux distro or version of FreeBSD you're using, such as "setting hostname centos"), carefully select the one that seems the most authoritive (for example, the Ubuntu "howto guide" for Ubuntu, Redhat's support information for RedHat etc) and carefully follow the instructions.