Solving ‘host name lookup failure’ problems in sendmail

This is documentation of how to fix one of the problems that will manifest itself in host name lookup failure error messages in sendmail. I’ll be using “guy” as masculine throughout here, but I’m not meaning to point any fingers. It could have been a gal. I’ll also be using the domain domain.bad which is not real, but which I’m using as shorthand for “any domain that doesn’t have a valid MX record that you’re trying to mail to.”

The other day, I was trying to email a guy. His domain resolves just fine, but whenver I would try to send email, I’d get a host name lookup failure, and the mail wouldn’t go through. A little digging showed me the problem:

davep : 101 % dig domain.bad MX

; <<>> DiG 2.2 <<>> domain.bad MX 
;; res options: init recurs defnam dnsrch
;; got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 33168
;; flags: qr rd ra; Ques: 1, Ans: 0, Auth: 0, Addit: 0
;;      domain.bad, type = MX, class = IN

;; Total query time: 3 msec
;; FROM: nerdcentral to SERVER: default -- XXX.XXX.XXX.XXX
;; WHEN: Sat Mar 13 10:51:58 2004
;; MSG SIZE  sent: 29  rcvd: 29

That is, there’s no MX record for the domain. So I proceeded to fix the problem in sendmail.

The first step is I have to build a mailertable. So I go into /etc/mail and (as root) edit mailertable so it contains the following (if it’s not there, go ahead and create it):

domain.bad	smtp:[domain.bad]

The square brackets are very important. They tell sendmail to send to the domain whether or not there is an MX record in the DNS. If I don’t put in the square brackets, I have the same problem whether or not I do all this work.

Once you’ve built that file, you need to make a database file from it. Since I know I’ll probably do this again, and won’t remember the magic invocation, I add it to a Makefile I keep in /etc/mail at the same time. The lines I add to the makefile are (the second is the command you’ll use if you’re doing this manually):

mailertable.db: mailertable
        makemap hash mailertable <mailertable

The almost-final step is to turn on mailertable support in sendmail. So log in as root, go to /usr/share/sendmail/cf and edit up the .mc file, adding the following line (note that the funny quotes here are important):

FEATURE(`mailertable', `hash /etc/mail/mailertable')

Once that’s done, and you’ve copied the resulting file over to /etc/mail, just restart sendmail. The simplest way to do this is to find the pid (I use ps -ax|grep sendmail) of sendmail and then HUP it with: kill -HUP pid.

That should do it. Remember that by doing this, you’re only solving the problem of the missing MX record for yourself, so you should probably drop a note to the admin for the domain that has the problem and remind them that they should have an MX record as part of their DNS.

Copyright 2009, Dave Polaschek. Last updated on Mon, 15 Feb 2010 14:09:35.