theforeman/foreman_maintain

Check: Incorrect /etc/hosts entry

Closed this issue · 4 comments

lzap commented

I very often see this:

IP_ADDRESS ALIAS FQDN

Which leads to incorrect reverse resolution (e.g. hostname -f). It must be:

IP_ADDRESS FQDN ALIAS

Or

IP_ADDRESS FQDN ALIAS1 ALIAS2 ...

But not the other way around.

I was hoping getent would do some kind of validation on hosts file, but it seems like it just ignores the problem and runs anyway. As I understand it, within hosts file, both fqdn and aliases may contain periods . - how does one tell them apart?

lzap commented

Our installer already tries to resolve $(hostname -f) and if this fails it does not want to continue. We could add the same check and also maybe for reverse DNS record as well (must exist).

The problem is quite often incorrect ordering in hosts but you are right that it is hard to check this. Maybe just try to check if alias is subset of fqdn string and if not issue warning, just try to catch the obvious case and ignore the others (different aliases). It is very often in the form of IP host.test.com host (the correct form). Just make sure this is just warning not error.

Or if this turns out to be too complicated let's simply drop this and close, was just an idea. I see this very often.

lzap commented

Only check /etc/hosts, do not check hostname output that's job installer. Correct entries are:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
1.2.3.4 server.example.com
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
1.2.3.4 server.example.com server
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
1.2.3.4 server.example.com serveralias1 serveralias2

Incorrect entry:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
1.2.3.4 server server.example.com
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
1.2.3.4 serveralias1 severalias2 server.example.com

Where 1.2.3.4 is one of servers known IP addresses.