5

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.

4
  • 2
    Wouldn't this be a security risk if it were even possible?
    – DWilliams
    Commented Apr 8, 2010 at 19:36
  • Probably, but I thought it was worth asking. Commented Apr 8, 2010 at 19:39
  • See also superuser.com/questions/381138/… Commented Nov 21, 2012 at 22:46
  • Great question. My VPN client overwrites my /etc/hosts file when I connect, so this would help me persist custom entries, if it can be done.
    – majorgear
    Commented Aug 9, 2023 at 21:45

2 Answers 2

3

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)?

0
6

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.

2
  • 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.
    – bogeymin
    Commented Oct 29, 2013 at 13:33
  • @bogeymin do you have a snippet of how that script looks like?
    – fuxes
    Commented Apr 24, 2018 at 15:27

You must log in to answer this question.

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