/etc/hosts 单进程

Vla*_*lov 5 networking linux

是否可以直接为可执行文件设置域名映射?就像我们编辑 /etc/hosts/ 然后运行可执行文件一样。

例子:

$ ping google.com
PING google.com (74.125.232.48) 56(84) bytes of data.
$ magic-command -m google.com=127.0.0.1 ping google.com
PING google.com (127.0.0.1) 56(84) bytes of data.
Run Code Online (Sandbox Code Playgroud)

小智 5

可以创造性地使用 LD_PRELOAD 和 RTLD_NEXT 来拦截大多数对 libc 的调用。谷歌这些字符串,那里有很多信息。拦截对 的调用open,用您自己的文件替换/etc/hosts. 它应该工作。