extension for /etc/hosts

Is it possible to extend the file /etc/hosts on ubuntu16.04?

I have many ubuntu-servers, all servers should use the same /etc/hosts file, except some special entries. My preffered solution would be an directory (/etc/hosts.d) with some extra files. Then I would be able to copy the original hosts file to every server and store a specialized file in the directory.

Any solutions? Thanks.


No, it's not possible using standard mechanisms.

derobert in his answer on Unix.SE suggested the following workarounds:

'There are a couple approaches you could use instead:

  • Set up a (possibly local-only) DNS server. Some of these give a lot of flexibility, and you can definitely spread your host files over multiple files, or even machines. If you're trying to include the same list of hosts on a bunch of machines, then DNS is probably the right answer.

  • Set up some other name service (NIS, LDAP, etc.). Check the glibc NSS docs for what is supported. Personally, I think you should use DNS in most all cases.

  • Make yourself an /etc/hosts.d directory or similar, and write some scripts to concatenate them all together (most trivial: cat /etc/hosts.d/*.conf > /etc/hosts, though you'll probably want a little better to e.g., sort), and run that script at boot, or from cron, or manually whenever you update the files.