[TriLUG] Syntax checker for /etc/hosts ?

Jeremy Portzer jeremyp at pobox.com
Thu Oct 24 16:58:27 EDT 2013


Hi TriLUG,

Is there any standard command to check the syntax and "sanity" in 
/etc/hosts?
While I could write a short script easily enough to do this, I thought 
it might be a common problem and there may be some other standard way to 
check it.

We have a lot of "junior" sysadmins and they are constantly making 
mistakes with /etc/hosts .  I'd really like to parlay this into the um, 
retraining of some of these people (perhaps to another job entirely!), 
but in the mean time we need to find their mistakes. Typical errors:
* Putting a hostname first followed by the IP address   [right below a 
list of other correct entries ... *sigh*]
* Listing the same IP more than once
* Listing the same host more than once
* Not listing the FQDN first after the IP address  (this is more of a 
site policy, but we want the format to be "IP FQDN aliases") .

And yes I know that we should be using DNS and/or configuration 
management tools, and we in fact do use both, but there are lots of 
one-offs and exceptions in our environment where manual hosts files will 
still be in use for a while.

Thanks,
Jeremy


More information about the TriLUG mailing list