Beside the LD_PRELOAD tricks. A simple alternative that may work on a few systems would be to binary-edit a copy of the system library that handles hostname resolution to replace /etc/hosts with a path of your own.
For instance, on Linux:
If you're not using nscd, copy libnss_files.so to some location of your own like:
mkdir -p -- ~/lib &&
cp /lib/x86_64-linux-gnu/libnss_files.so.2 ~/lib
Binary(the shared library may be located elsewhere, e.g. /lib/libnss_files.so.2)
Now, binary-edit the copy to replace /etc/hosts in there to something the same length like /tmp/hosts.
perl -pi -e 's:/etc/hosts:/tmp/hosts:g' ~/lib/libnss_files.so.2
Edit /tmp/hosts to add the entry you want. And use
export LD_LIBRARY_PATH=~/lib
for nss_files to look in /tmp/hosts instead of /etc/hosts.
Instead of /tmp/hosts, you could also make it /dev/fd//3 (here using two slashes so that the length of /dev/fd//3 is the same as that of /etc/hosts), and do
exec 3< ~/hosts
For instance which would allow different commands to use different hosts files.
If nscd is installed and running, you can bypass it by doing the same trick, but this time for libc.so.6 and replace the path to the nscd socket (something like /var/run/nscd/socket) with some nonexistent path.