Linux NSS library supporting per-user hosts resolution using ${XDG_CONFIG_HOME}/hosts
or ~/.hosts
- Compile the code:
$ make
- Install the resulting library:
$ sudo make install
- Preprend the NSS module to the hosts line of
/etc/nsswitch.conf
:
hosts: homehosts files dns
- Uninstall the library:
$ sudo make uninstall
- Remove the added module from
/etc/nsswitch.conf
.
- Create
~/.hosts
file and put some host names in it like/etc/hosts
:
127.0.0.1 myhost.example.net
- Check it
$ getent hosts myhost.example.net
$ ping myhost.example.net
Note that looking up the using host
or nslookup
will not work as these tools query DNS directly, sidestepping NSS.
It is better to have FQDN as in /etc/hosts
, as well in ~/.hosts
files, eg.
198.18.1.1 frodo.baggins.theshire
instead of
198.18.1.1 frodo
in order to avoid dns suffix-list expansion by libresolv when unneccessary.
Refer to ndots
option at resolv.conf(5).
Please submit issues via PR to some file <TITLE>.txt
or <TITLE>.md
on issues
branch.