小弟最近做了一段程序,在远程机房的linux的apache上跑,代码如下$ip = gethostbyname("www.google.com");
echo "IP is:".$ip;但是返回的ip却是www.google.com,同样的代码在windows上跑却返回了64.233.189.104,即使是本地linux上也也是返回64.233.189.104google了很久,可能是远程linux上的DNS问题,但是就是不知道如何解决,希望高手指点一二。

解决方案 »

  1.   

    你在远程机房的linux上 执行 ping www.google.com 试试
    如果不能解析出IP,那就需要给你的linux设置DNS
    修改 /etc/resolv.conf文件中nameserver的配置
      

  2.   

    ping www.google.com的话是可以解析出ip的
    /etc/resolv.conf中的nameserver是做过配置的也就是说在linux上上网下载东西是没有问题的,但是就是在执行php的函数的时候,解析不出ip,会不会是php或者是apache的问题
      

  3.   

    有可能是dns逆向解析的问题,因为我的是这样.
      

  4.   

    $dbarr['site_ip'] = gethostbyname( $config['SITE_NAME']);
    if(ip2long($dbarr['site_ip'])!==-1)list($dbarr['site_ip']) = gethostbynamel( $config['SITE_NAME']);
    //更新HOST信息
    if(ip2long($dbarr['site_ip'])!==-1)
    if($dbarr['site_ip']) $host_name = gethostbyaddr($dbarr['site_ip']);
      

  5.   

    Returns the IPv4 address or a string containing the unmodified hostname on failure. 
    function getAddrByHost($host, $timeout = 3) {
       $query = `nslookup -timeout=$timeout -retry=1 $host`;
       if(preg_match('/\nAddress: (.*)\n/', $query, $matches))
          return trim($matches[1]);
       return $host;
    }