U

userhosts

Redirect access to /etc/hosts to another file

userhosts - Redirects accesses to /etc/hosts to another file.

Rationale

The need is to customise hostname (reverse )resolution for a single process (and potentially its children), potentially resolving conflicting domain names to different addresses and vice-versa.

libnss' HOSTALIASES feature only allows mapping between domain names, not between names and addresses, so it is not powerful enough.

Limitations

This library relies on LD_PRELOAD mechanism, so it inherits its limitations (it will not work on suid binaries, ...).

Requirements

  • make
  • a C compiler
  • glibc (source uses RTLD_NEXT)

Building

Just run "make".

Usage

$ HOSTS=/path/to/custom/hosts LD_PRELOAD=/path/to/userhosts <command>

userhosts is also an executable wrapper that appends itself to LD_PRELOAD:

$ HOSTS=/path/to/custom/hosts userhosts <command>