CartMetrix - Do you know yours?

« SSH-Keygen For Public Key Authentication | Home | Quickly Copy MySQL Database to Remote Host »

8/23/2007

PHP gethostbyname() and DNS

For PHP’s gethostbyname() to work properly, the server’s DNS must be properly configured with available nameservers in /etc/resolv.conf (on Linux boxes). Without a work domain name resolution kit, gethostbyname() returns the hostname supplied to the function.

Make sure /etc/resolv.conf contains several nameservers to query. The format is

nameserver xxx.xxx.xxx.xxx
nameserver yyy.yyy.yyy.yyy

Where xxx.xxx.xxx.xxx and yyy.yyy.yyy.yyy are the IP addresses of nameservers the host has permission to use.

OpenDNS is a free DNS service that allows public access to their nameservers at:

208.67.222.222
208.67.220.220

To use in /etc/resolv.conf use:

nameserver 208.67.222.222
nameserver 208.67.222.220

Using OpenDNS’s nameservers could even boost your server’s performance. Their goal is to provide some of the faster domain name resolvers on the internet for free.

Popularity: 35%

Trackback:

Related Posts

  • No related posts

4 Responses to “PHP gethostbyname() and DNS”

  1. Pavel Titov said:

    To boost server’s performance it’s better to have a local (preferably within the same network segment) caching nameserver. BTW it can forward requests to the OpenDNS, although I prefer using co-location facility’s DNS.

  2. damonp said:

    Local nameservers are a better setup if the datacenter ISP maintains a high QOS on its DNS servers and doesn’t overload them with too many hosts for each nameserver. Many ISPs don’t which is why I’ve seen better response in a lot of cases using a fast service like OpenDNS.

  3. Pavel Titov said:

    In this case it’s still worth to set up own caching NS and forward requests to OpenDNS.

  4. damonp said:

    For optimum performance… yes. However, setting up a caching nameserver takes time (thus $$) and some know how or you can totally hose your server. Using a third party DNS takes two seconds and almost anyone can follow the few steps it takes to configure.

    If everyone could setup a nameserver properly on their own, there are a lot of us that would be out of a job. :-(

Post your opinion

Verification Image

Please type the letters you see in the picture.

Subscribe without commenting


damonparker.org is proudly powered by WordPress
Entries (RSS) and Comments (RSS).

copyright © 2002-2008 damonparker.org. all rights reserved.

Close
E-mail It