Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Some time ago we had an issue with our network infrastructure and php with curl.

Our Network infrastructure is fairly simple.

LoadBalancer/Firewall => 5 servers

The Domainname of our website is set to the ip of the Loadbalancer, of course. But calling curl from one of the servers did result in a timeout. It appears that a server could not call for its own domain it is serving. So we had to set the domains via /etc/hosts to the sever itself.

But now We have implemented a Varnish in front of the Loadbalancer, which we want to automatically purge, once a change on a page happens. So now we need to call the domain Sadly this call what be resolved to the server itself instead of the varnish, because of the /etc/hosts entries.

So now I am wondering, if you could resolve domain names differently for different services :)

share|improve this question
Get rid of the /etc/hosts entries and fix whatever was causing the problem rather than ignoring it. – David Schwartz May 22 '12 at 11:11
I do not ignore the problem, rather fixing it with the help of the /etc/hosts. Our network infrastructure does not allow to got out of the firewall and enter it again... – mlaug May 22 '12 at 12:48
There is no reason the network infrastructure should disallow a machine from reaching a service that it has a legitimate need to reach. The /etc/hosts hack was done instead of solving the actual problem by allowing the access. – David Schwartz May 22 '12 at 13:09
up vote 1 down vote accepted

To answer the question, the only way I am aware of - but never seen used - is via the RES_NAMESERVER environment variable.

To answer your problem, I agree with David Schwartz that you need to remove the /etc/hosts entries because it will only cause you problems. Change your approach to either change the firewall or go directly to a backend host.

share|improve this answer

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.