How do I create my own custom hosts file?
For some specific reasons I don't want to edit the /etc/hosts
file and that is why I needed to create my own hosts file in suppose ~/hosts
and use it for all IP to HOSTNAME mapping along with the system's /etc/hosts
file. How will I be able to do this?
Solution 1:
Using the environment variable HOSTALIASES
:
-
Define the environment variable
HOSTALIASES
export HOSTALIASES=~/.hosts
-
Create your private
hosts
file and add a test entryecho 'myprivategoogle www.google.com' > ~/.hosts
-
Start a test
curl myprivategoogle
without the entry in
~/.hosts
you would getcurl: (6) Could not resolve host: myprivategoogle
with the entry you have
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>302 Moved</TITLE></HEAD><BODY> <H1>302 Moved</H1> The document has moved <A HREF="http://www.google.com/">here</A>. </BODY></HTML>