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 www.example.com/url_to_purge. 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 :)

  • Get rid of the /etc/hosts entries and fix whatever was causing the problem rather than ignoring it. 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. May 22 '12 at 13:09

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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