Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 27th August 2009, 14:04
Craig Craig is offline
Member
 
Join Date: Dec 2006
Posts: 56
Thanks: 1
Thanked 3 Times in 1 Post
Default PHP GetHostByName for non-existent domains returns server IP

I can dig from the centos command line and DNS queries for non-existent domains return the expected results, basically nothing.

But, if I use PHP functions, the IP of the server is returned.

Also, if I try to use PHP Pear's HTTPRequest library to fetch a page from a non-existent domain, the root page of the server is again returned.

I haven't tried PHP's cURL yet but I would guess that is the same.

Googling this brings up a number of people who have had the same problem over the years, going back to 2001 but there is NOT ONE SINGLE mention of a solution.

I thought that might mean that those with the problem "simply" reinstalled everything and it all just worked but I tried that, just now, it didn't work.

I'm running Centos 5.3 with ISPConfig v.2 running and other than this PHP problem, it is all working fine.

Any help would be greatly appreciated!

I should add that a dev server running from the same NAT reacts correctly so it seems that it is something in the way the problem server is configured although all the network configuration was done using the GUIs so I don't think it could be a typo or something like that.

I should also add that the IP address returned for non-existent domains is the server's external IP address, as opposed to its internal NAT address. I haven't found anywhere that the server's external IP is in any configuration files so PHP seems to be getting it through DNS one way or another.
__________________
cass-hacks.com

Last edited by Craig; 27th August 2009 at 19:17. Reason: Added information about a second server and External vs. Internal IP address
Reply With Quote
Sponsored Links
  #2  
Old 28th August 2009, 09:40
Craig Craig is offline
Member
 
Join Date: Dec 2006
Posts: 56
Thanks: 1
Thanked 3 Times in 1 Post
Default

More info about what is not the problem.

Some references in Google mention permissions issues, namely /etc/resolv.conf not being accessible to user "apache" and therefore PHP can't find how to resolve things properly. The common test is to run a test script in CLI under user root to test this. This is not the problem because the test script also fails the same way, resolution of non-existent domains continue to point to the server's external IP address, when run as root in CLI.

I thought that maybe there was a domain name conflict so I created a dummy domain name totally different than anything on the box and added it and the server's IP to my hosts file and everything ran as expected but, resolving non-existent domains still point to the server's external IP address.

I also temporarily replaced the production server with a dev box, on which it works correctly, and the dev box continued to work correctly. This is probably redundant but worth the 5 minutes it took to test it.

I'm at the point now of scripting a work around in PHP so that:

1) The domain name to be resolved is first compared to the server name and if the same or one includes sub-domains of the site's domain, the site's external IP is returned.

2) If they are not the same, gethostbyname() is then called on the query domain.

3) If the call to gethostbyname() returns the site/server's IP, the test function returns the original query domain. This is what will happen on the box with broken DNS resolution in PHP and so the result of the function call is as it should be from a call to gethostbyname().

4) If the call to gethostbyname() returns an actual IP address that is not the site/server's, it is returned, again, as it should be.

5). If the call to gethostbyname() returns the query domain, as it should on a box with properly functioning PHP DNS resolution if the domain is a non-existent domain, the test function returns the original query domain.

Fortunately there is only one site/service on this box that does php dns or it would really be a pain.

Although I do have a kluge that works, if anyone can suggest how to track it down, I would be very happy.
__________________
cass-hacks.com
Reply With Quote
  #3  
Old 27th June 2012, 19:44
sel sel is offline
Junior Member
 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default

I had the same problem. What I've done is i've removed this line:
domain DOMAIN_NAME_HERE
from /etc/resolve.conf file
After this gethostbyname started to work.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code for PHPMyAdmin is not parsed parkerj Installation/Configuration 3 26th May 2009 13:40
ISP Config hesitation when opening web pages frankb Installation/Configuration 7 15th December 2008 13:06
Postfix - Relay access denied gotting Server Operation 3 23rd April 2008 14:06
Email - Ueb-Miau mazhar Installation/Configuration 5 21st December 2005 10:01
The Perfect Setup Suse 9.3 - Postfix problems new_bee05 HOWTO-Related Questions 20 25th November 2005 02:30


All times are GMT +2. The time now is 12:29.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.