Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Dec 2009 13:37:18 +0100
From:      Olivier Mueller <om-lists-bsd@omx.ch>
To:        freebsd-questions@freebsd.org, freebsd-net@freebsd.org
Subject:   networking differences with php file_get_contents under 6.1 and 7.2 ?
Message-ID:  <1260880638.26162.26.camel@ompc.insign.local>

next in thread | raw e-mail | index | archive | help

Hello,

I just observed a strange thing on 2 servers with a very similar setup
(apache config, php version/ini, virtual ip addresses, etc.) but under 2
different FreeBSD versions. 

I would like to understand if is related to the OS version and why. 

To test, I have a short php script which calls itselfs with
file_get_contents() : under 6.1 the source IP is the one from apache
virtual host, and under 7.2 it's the first interface from server : why
this difference?  Is it a new feature/change in 7.x, or a bug(fix)? 

If I do a request on an external server (like
http://crazzy.se/get_ip.php ) it always return the main server IP. Only
when I do the call locally and under 6.1 it's not the case... 




Under 6.1 I get this output (scroll down for the script):
 test1.example.com = virtual host under 10.0.0.239
 main server ip = 10.0.0.210

------------------------------------------------------------
Initial call:
SERVER_ADDR: 10.0.0.239
REMOTE_ADDR: 10.0.0.12

calling... http://test1.example.com/iptest_om.php?recall=1
------------------------------------------------------------
Call from self:
SERVER_ADDR: 10.0.0.239
REMOTE_ADDR: 10.0.0.239 (client)     <<<<====== ????
end
------------------------------------------------------------
end

ifconfig: 

bce0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	options=3b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU>
	inet6 fe80::218:feff:fe31:8ae4%bce0 prefixlen 64 scopeid 0x1 
	inet 10.0.0.210 netmask 0xffffff00 broadcast 10.0.0.255
	inet 10.0.0.212 netmask 0xffffff00 broadcast 10.0.0.255
	inet 10.0.0.239 netmask 0xffffff00 broadcast 10.0.0.255



and under 7.2:   (test2.example.com = 10.0.0.122, main = .120)

------------------------------------------------------------
Initial call:
SERVER_ADDR: 10.0.0.122
REMOTE_ADDR: 10.0.0.12 

calling... http://test2.example.com/iptest_om.php?recall=1
------------------------------------------------------------
Call from self:
SERVER_ADDR: 10.0.0.122
REMOTE_ADDR: 10.0.0.120 (client)         <<====== ok

end
------------------------------------------------------------
end


ifconfig:

bce0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
	options=1bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4>
	ether 00:1f:29:06:9c:38
	inet 10.0.0.120 netmask 0xffffff00 broadcast 10.0.0.255
	inet 10.0.0.122 netmask 0xffffff00 broadcast 10.0.0.255
	inet 10.0.0.123 netmask 0xffffff00 broadcast 10.0.0.255





test script: 

<?php

        if ($_GET["recall"] != 1) {
                print "<hr>\n";
                print "<b>Initial call:<br>\n";
                print "SERVER_ADDR: " . $_SERVER["SERVER_ADDR"] . "<br>\n";
                print "REMOTE_ADDR: " . $_SERVER["REMOTE_ADDR"] . "<br>\n";
                print "<br>\n";
                $url = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"] . "?recall=1";
                print "calling... $url<br>\n";

                print "<font color=blue>\n";
                echo file_get_contents($url);
                print "</font>\n";
                print "<hr>\n";
        }

        if ($_GET["recall"] == 1) {
                print "<hr>\n";
                print "<b>Call from self:<br>\n";
                print "SERVER_ADDR: " . $_SERVER["SERVER_ADDR"] . "<br>\n";
                print "REMOTE_ADDR: " . $_SERVER["REMOTE_ADDR"] . " (client)<br>\n";
                print "<br>\n";
                print "\n";
        }

        print "end<br>\n";

?>



Thanks for any feedback & regards,
Olivier




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1260880638.26162.26.camel>