Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Wouldn't this be a security risk if it were even possible? – DWilliams Apr 8 '10 at 19:36
Probably, but I thought it was worth asking. – lawnmowerlatte Apr 8 '10 at 19:39
See also… – therefromhere Nov 21 '12 at 22:46
up vote 3 down vote accepted

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

share|improve this answer
Definitely solved my problem. Thanks! – lawnmowerlatte Apr 8 '10 at 19:47

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|improve this answer
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 Oct 29 '13 at 13:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.