Used to override DNS settings for a single process (and its decendants) using the glibc resolv
See my post about it:
http://blog.backslasher.net/dns-override.html
The library monkeypatches fopen and looks for calls for /etc/resolv.conf, and returns a file pointer to a memory stream containing a customized version of resolv.conf.
The new resolv.conf is built by the script based on the current resolv.conf and passed as the RESOLV_CONF environment variable.
We then use LD_PRELOAD to insert our library (and version of fopen) before the "real" one.
It then execs the wanted binary.
Since both LD_PRELOAD and RESOLV_CONF are environment variables, they'll pass on to subprocesses too.
- Build
dns-override.soif needed (make dns-override.so) - determine replacement DNS servers
- run desired file like so:
./dns-override.sh -s SERVER BINARY)
Multiple servers can be specified, see script
Run LD_PRELOAD=./dns-override.so:$LD_PRELOAD RESOLV_CONF=<new resolv conf contents> <binary>.
Do note that I'm only covering fopen which isn't used by all programs. For instance, python will be fooled but perl will not.
bats, perl and python are required.
- Run
make test