libnss_homehosts
libnss_homehosts copied to clipboard
Linux NSS library supports ~/.hosts
libnss_homehosts
Linux NSS library supporting per-user hosts resolution using ${XDG_CONFIG_HOME}/hosts or ~/.hosts
Install
- 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
- Uninstall the library:
$ sudo make uninstall
- Remove the added module from
/etc/nsswitch.conf.
Usage
- Create
~/.hostsfile 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.
Performance
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).
issues
Please submit issues via PR to some file <TITLE>.txt or <TITLE>.md on issues branch.