Is there a way to 'include' a separate file in /etc/hosts?

9,163

Solution 1

I do not believe there is any way to include other files into a hosts file.

Would it be possible to make /etc/hosts group-writable by a group that only includes you (and any other users who need to edit it)?

Solution 2

Keep a hosts.base file and then write a simple script to build a complete, combined hosts file with that hosts.base file and the other files you want to include. You can cron it or execute on demand.

Share:
9,163

Related videos on Youtube

lawnmowerlatte
Author by

lawnmowerlatte

Support turned QA turned Release Engineering/DevOps. I focus on product delivery automation and automated testing. I work mostly with Python, but dabble in Groovy and Bash. I work with containers, VMs and various software packaging technologies.

Updated on September 17, 2022

Comments

  • lawnmowerlatte
    lawnmowerlatte almost 2 years

    Is there any way to 'include' another file within the /etc/hosts file? Particularly I want to include a non-protected (-rw-rw-rw) file so I can easily edit it in something like TextMate without having to issue sudo vi /etc/hosts

    I'm on OS X, but as far as I know, this should be relevant in other *nix OSs.

    • DWilliams
      DWilliams about 14 years
      Wouldn't this be a security risk if it were even possible?
    • lawnmowerlatte
      lawnmowerlatte about 14 years
      Probably, but I thought it was worth asking.
    • pion
      pion over 11 years
  • bogeymin
    bogeymin over 10 years
    This is how I do it for local development. I keep a separate file for each project in a specific location, and run a script that combines the base with the project files.
  • fuxes
    fuxes about 6 years
    @bogeymin do you have a snippet of how that script looks like?