User-specific hosts file to complement /etc/hosts

Any user can create a personal list of hosts to complement the entries in the /etc/hosts file.

The functionality is implemented in glibc. You can define a custom hosts file by setting the HOSTALIASES environment variable. The names in this file will be picked up by gethostbyname (see documentation).

$ echo 'g www.google.com' >> ~/.hosts
$ export HOSTALIASES=~/.hosts
$ wget g -O /dev/null
Slightly edited from: Can I create a user-specific hosts file to complement /etc/hosts? – Unix & Linux Stack Exchange

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.