Sendmail And Fully Qualified Domain Names

Recently I attempted to get sendmail to work between two machines in my internal test network. Since it's my own small network I tend to use short unqualified hostnames such as "grey" or "white". As you may know this presents certain challenges when working with sendmail since sendmail prefers FQDNs (fully qualified domain names). In this blog entry I'll talk about what those challenges are and what I think is the most straight forward way to get sendmail to work in such a network.

On Fedora 10 if you choose a short hostname such as "grey" at install time the relevant entry in /etc/hosts ends up looking like the following:    localhost.localdomain localhost grey

Assuming sendmail's configuration files have been left in their default state sendmail uses the logic described on this page (seach for "Sendmail tries to find") to determine it's own hostname. First sendmail() invokes gethostbyname() on it's hostname of "grey" and conclude that "localhost.localdomain" is it's FQDN.

You'll find that if you don't alter either /etc/hosts or /etc/mail/ that each sendmail server will think it's hostname is "localhost.localdomin". This results in errors such as "Real domain name required for sender address" when the receiving sendmail server is told that the email comes from "localhost.localdomin".

Additionally if the name found does not have a "." in it sendmail iterates through the aliases (the tokens following the first token in /etc/hosts) until it finds an alias that has a ".". If sendmail is still not able to find a name with a "." (if, for example, "localhost.localdomain" had been removed from the above) it waits 60 seconds and tries again. This results in vary slow boot times with messages such as the following:

Mar  6 11:50:49 localhost sendmail[2450]: My unqualified host name (grey) unknown; sleeping for retry

This logic, including the hardcoded 60 second sleep, can be seen myhostname() in sendmail/daemon.c in the sendmail source.

One approach is to simply set the domain name explicitly in in /etc/mail/ like this:

define(`confDOMAIN_NAME', `grey')dnl

Note that sendmail still needs to find a FQDN for it's hostname on start up even if the above is used.

Alternatively, if you prefer to not hardcode the hostname in files where it currently is not you can try to make up a top level domain and put it in /etc/hosts prior to any other FQDNs; something like this:    localhost grey.my_domain localhost.localdomain grey

But this is a less desirable approach since it may have some side effects.