是否在本地进行名称解析? [英] process-local override of name resolution?
问题描述
我有一些测试代码,我想让几个主机名在测试时解析为回送.部署后,此代码将酌情使用常规系统名称解析.测试和部署主机是最新的Linux发行版(例如,SLES11SP1).
I have test code that I want to have a couple of hostnames resolve to the loopback while testing. When deployed, this code will use the normal system name resolution as appropriate. Test and deployment host are recent linux distros (SLES11SP1, e.g.).
我想在不成为超级用户的情况下为单个进程覆盖主机名解析.有没有办法以这种狭窄的方式来操纵nsswitch
/hosts
行为?
I'd like to override hostname resolution for a single process, without being superuser. Is there a way to manipulate the nsswitch
/hosts
behavior in such a narrow fashion?
是的,我当然可以覆盖主机名,但是我不愿意(除非此功能确实不可用).
Yes, of course I could override the hostnames themselves, but I prefer not to (unless this feature really isn't available).
glibc
的HOSTALIASES
功能听起来确实像我想要的-但在我调查的主机之间,其可用性/有效性似乎不一致.在某些时候,它被添加到不安全的环境变量列表中.但这是否意味着它会被全局忽略或仅在suid二进制文件中被忽略?它对getnameinfo
()的程序仍然有效吗?
glibc
's HOSTALIASES
feature sounds like exactly what I want -- but its availability/effectiveness seems inconsistent among the hosts I surveyed. At some point, it was added to be among a list of insecure environment variables. But does that mean it's ignored globally or only in suid binaries? Will it still work for programs which do getnameinfo
()?
更多
IMO,HOSTALIAS
胜出.对于不尊重nscd
的平台(例如我的(SuSE)),禁用nscd
是一种解决方法.也许他们会发布修复程序.
More edit:
IMO, HOSTALIAS
wins hands down. Disabling nscd
is a workaround for platforms which don't respect it -- like mine (SuSE). And maybe they will release a fix.
推荐答案
LD_LIBRARY_PATH获胜!
LD_LIBRARY_PATH for the win!
http://tldp.org/HOWTO/Program-Library -HOWTO/shared-libraries.html
也: http://www.linuxjournal.com/article/7795
这篇关于是否在本地进行名称解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!