Is there a way to 'include' a separate file in /etc/hosts?
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.
Related videos on Youtube
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, 2022Comments
-
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 issuesudo vi /etc/hosts
I'm on OS X, but as far as I know, this should be relevant in other *nix OSs.
-
DWilliams about 14 yearsWouldn't this be a security risk if it were even possible?
-
lawnmowerlatte about 14 yearsProbably, but I thought it was worth asking.
-
pion over 11 yearsSee also superuser.com/questions/381138/…
-
-
bogeymin over 10 yearsThis 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 about 6 years@bogeymin do you have a snippet of how that script looks like?