Per-user hosts file
Is there a way to define host aliases (like in /etc/hosts
) on a per user basis, i.e. in a file /home/user/.hosts
?
My primary objective is to easily share host aliases via rsync between the machines in my small lan. Since there is no machine that will be reliably always connected, a DNS server is not an option (right?).
Thank you.
A better solution would be to install Avahi and libnss-mdns, and then use HOSTNAME.local
addresses.
These names would not be per-user, but would solve your stated objective of having common names for all machines across a LAN.
See https://github.com/figiel/hosts for a way to do exactly what you ask.
That is a small library, loaded via LD_PRELOAD and which overrides gethostbyname() and several related functions that programs use for DNS resolution. It works well for me. The only caveat that I found is that Chrome web browser does not use native DNS resolution, but instead implements its own DNS client. To solve that problem you need to disable Chrome's DNS client.