Linux – Process Local Overrides Name Resolution?

Process Local Overrides Name Resolution?… here is a solution to the problem.

Process Local Overrides Name Resolution?

I

have test code and I want to resolve several hostnames to loopback when testing. Once deployed, this code will use normal system name resolution as appropriate. The test and deployment host is the latest Linux distribution (for example, SLES11SP1).

I want to override hostname resolution for a single process, not the super user. Is there a way to manipulate nsswitch/hosts behavior in such a narrow way?

Yes, I

can certainly override the hostname myself, but I don’t want to do that (unless this feature is really not available).


Edit:

glibc's hostaliases feature sounds exactly what I was looking for – but its usability/effectiveness seems inconsistent across the hosts I investigated. At some point, it is added to the list of unsafe environment variables. But does that mean it’s ignored globally or only in suid binaries? Does it still work with programs that execute getnameinfo()?


More edits:
IMO, HOSTALIAS WON EASILY. Disabling nscd is a workaround for platforms that don’t adhere to it — such as My Platform (SuSE). Maybe they will release a fix.

Solution

Related Problems and Solutions