如何创建自己的自定义主机文件?

由于某些特定原因,我不想编辑/etc/hosts文件,这就是为什么我需要在假设~/hosts创建我自己的主机文件并将其用于所有IP到HOSTNAME映射以及系统的/etc/hosts文件。 我怎么能这样做?

使用环境变量HOSTALIASES

  1. 定义环境变量HOSTALIASES

     export HOSTALIASES=~/.hosts 
  2. 创建私有hosts文件并添加测试条目

     echo 'myprivategoogle www.google.com' > ~/.hosts 
  3. 开始测试

     curl myprivategoogle 

    你没有~/.hosts输入

     curl: (6) Could not resolve host: myprivategoogle 

    您的条目

      302 Moved 

    302 Moved

    The document has moved here.