Is it possible to set domain names mapping directly for an executable? As if we edit /etc/hosts/ and then run the executable.


$ ping google.com
PING google.com ( 56(84) bytes of data.
$ magic-command -m google.com= ping google.com
PING google.com ( 56(84) bytes of data.
  • 1
    Why? / What are you trying to accomplish?
    – Nix
    Commented Jun 27, 2011 at 17:24
  • Perhaps this should have been migrated to unix.SE instead of ServerFault?
    – Caleb
    Commented Jun 28, 2011 at 8:18

1 Answer 1


It is pissible to intercept most calls to libc with a creative usage of LD_PRELOAD and RTLD_NEXT. Google these strings, there's a lot of info out there. Intercept calls to open, substitute your own file for /etc/hosts. It should work.

  • Intercepting calls to open() might not work for this case. See plash.beasts.org/wiki/PlashFAQs. You might need to intercept gethostbyname() or its friends instead.
    – netvope
    Commented Feb 16, 2012 at 6:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .