When trying to start sendmail or send a mail using a wordpress plugin, this error shows up in the maillog:

"My unqualified host name (foo.bar) unknown; sleeping for retry"

After Googling the best advice was, "add foo.bar to the /etc/hosts file", but it already is:     localhost localhost.localdomain     foo.bar

3 Answers 3


Simply changed:     localhost localhost.localdomain     foo.bar

To this     localhost localhost.localdomain foo.bar

Sendmail looks for a fully qualified domain (FQDN) name and will use the localhost.localdomain in the single line version.

  • 2
    fixed my problem. Just want to be clear, it is the hostname that should be put in this line. So first use hostname command find it, than add it to this line in \etc\hosts . Thanks, man.
    – Leon
    Jul 4, 2013 at 6:53
  • It didn't work for me Mar 13, 2018 at 19:12
  • or actually use a domain name that exists and is configured properly. At least if you want your mail to get delivered you should.
    – Sammitch
    Dec 29, 2018 at 1:41
  • just to clarify it a bit - the foo.bar should be your hostname, to get your hostname easily run $ hostname . Then add the shown hostname to that line as suggested in this solution
    – Shir Gans
    Nov 6, 2019 at 9:24

Simply adding the domain to your hosts files as @rjstelling suggests will only allow your mail to be sent, but it is incredibly unlikely to land in someone's inbox.

In order to send an email that won't be flagged as spam, to say nothing of the receiving server just terminating the delivery attempt or dropping the message, you need to be using a real, registered domain name with working DNS and an MX record.

And that is to say nothing for FCRDNS or any one of the dozens of things that you need to do to run a server whose email might actually be accepted most of the time. [if the internet gods deign to smile upon you even briefly] The true answer is that you probably shouldn't be running your own mailserver because it's simply not worth the work required to keep it in good standing. Look into mail services like SendGrid, MailChimp, etc.


The accepted answer:   localhost localhost.localdomain foo.bar

seems to work, but produces the errors in /var/log/syslog:

    sendmail[11655]: gethostbyaddr( failed: 1

But leaving just   localhost

in /etc/hosts, and removing the second line allows mail to get sent, and does not result in any errors.

Update: when doing sudo ...whatever.. there is a message sudo: unable to resolve host foo.bar, but looks like it does not affect anything..

BTW, to restart the hostname service without reboot:

    systemctl restart systemd-hostnamed

On Ubuntu 16.04, but should not be necessary for mail to work after editing /etc/hosts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.