/etc/hosts needs host, host.domain, and host.domain.

Hi all.

My servers all point sendmail to a mailhub, let's call it mailhub, with an FQDN of mailhub.domain.

In my sendmail file I put a trailing dot, thusly: mailhub.domain..

To my surprise, in /etc/hosts I needed the exact entry - having just the uQDN or omitting the trailing dot wouldn't work.

It appears also that /etc/resolv.conf isn't consulted (it doesn't add the search domain and then query /etc/hosts). Which leads me to think that the matching against /etc/hosts is a simple word-boundary delimited text search. Does that sound right?

Now I'm tempted to edit all of my /etc/hosts files and add new entries for each host with a trailing dot. (Just in case there's a program somewhere referring to it).

Thanks,
Scott
 
The trailing dot makes the domain name absolute. If you omit it, it might get overridden similarly to when you use an absolute path /... or a relative one .../....
Do you have a "search" clause in your /etc/resolv.conf?

Normally the domain name resolution (including /etc/hosts) should handle domain names without a trailing dot just fine (it's a shortcut according to RFC 1034, https://tools.ietf.org/html/rfc1034 , page 7).

It is not clear from your question exactly what "wouldn't work". If you ask a precise question and post the commands and an error message you're getting it would be easier to help.
 
It appears also that /etc/resolv.conf isn't consulted (it doesn't add the search domain and then query /etc/hosts).
It uses DNS or the hosts file, not a combination of both. And the hosts file is typically checked first. See nsswitch.conf(5).
Code:
hosts: files dns
 
Hi,

precise question: is it expected that an entry in /etc/hosts like:

Code:
127.0.0.1 host.domain

NOT resolve host.domain.? (NB: the trailing dot).

eg:
Code:
# grep test /etc/hosts
127.0.0.1               test.domain
# ping test.domain.
ping: cannot resolve test.domain.: Unknown host
# ping test.domain
PING test.domain (127.0.0.1): 56 data bytes

Also:

Code:
# grep google /etc/hosts
127.0.0.1               google.com
# ping -c 1 google.com
PING google.com (127.0.0.1): 56 data bytes
...
# ping -c 1 google.com.
PING google.com (216.58.199.78): 56 data bytes
 
You shouldn't use the trailing dot on URLs. The trailing dot should only be used inside DNS zone records.
 
Diversions aside :), are you saying the question in post #4 is so flawed that it can't be answered?

You shouldn't use the trailing dot on URLs. The trailing dot should only be used inside DNS zone records.

Given the above sentence directly conflicts with the Sendmail documentation, can you cite a reference or elucidate on why trailing dots are to be avoided (when specifying hosts, not URLs - which I assume break requests because of the Host: header)?

Thanks.
 
Given the above sentence directly conflicts with the Sendmail documentation
It assumes you're using DNS to resolve. Which begs the question, why aren't you using DNS? Managing hosts files is a royal pain in the posterior. Especially if you have hundreds of hosts to maintain.
 
It assumes you're using DNS to resolve. Which begs the question, why aren't you using DNS? Managing hosts files is a royal pain in the posterior. Especially if you have hundreds of hosts to maintain.

And that is the point. As soon as you have working DNS, use it. /etc/hosts is only there for the few cases where you need that information but do not (yet) have DNS.

And if you ever have something to add to /etc/hosts, the full proper and ugly way is (and has been for more than a decade):
Code:
192.0.2.3        plumpudding  plumpudding.example.com
192.0.2.3        plumpudding.example.com.
And the same again for v6
 
I really wish I started this thread with post 4. No-one has really had a swing at it yet. I would expect a "yes" or "no" or "that's odd".

To the other points raised - there are good reasons to use /etc/hosts. One of my hosts is a mail relay (for authenticated users) which has a tunnel to my internal network over which I want things like syslog. It's memory-constrained VM and so I don't want to run a DNS server just to resolve my syslog hostname. This is but one reason to use a static file for hostname resolution.

And if you ever have something to add to /etc/hosts, the full proper and ugly way is (and has been for more than a decade):

I've never seen/used the same host IP across different lines. Just for anyone's reference reverse lookups resolve to the first hostname listed on the first matching line.
 
Back
Top