Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


$ ping
PING ( 56(84) bytes of data.
$ magic-command -m ping
PING ( 56(84) bytes of data.
share|improve this question

migrated from Jun 27 '11 at 19:30

This question came from our site for professional and enthusiast programmers.

Why? / What are you trying to accomplish? – Nix Jun 27 '11 at 17:24
Perhaps this should have been migrated to unix.SE instead of ServerFault? – Caleb Jun 28 '11 at 8:18

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.

share|improve this answer
Intercepting calls to open() might not work for this case. See You might need to intercept gethostbyname() or its friends instead. – netvope Feb 16 '12 at 6:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.