10

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.

4
  • 4
    Has someone experience with the dotdee package? dotdee manpage. This seems to be a solution for me. Jul 21, 2016 at 4:27
  • 1
    Interesting idea, wasn't aware of that tool. But from the question you don't seem to need to generate the file dynamically. You might be better off considering using a full-fledged configuration management solution like Ansible and generate the files from templates.
    – techraf
    Jul 21, 2016 at 5:00
  • 1
    Good question. It would be very nice if /etc/hosts.d/ would work
    – guettli
    Feb 14, 2019 at 12:53
  • @guettli I suggest have a look at things like dnsmasq Feb 14, 2019 at 15:18

1 Answer 1

7

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .