Page 1 of 1

Multiple NICs question

Posted: Thu Oct 16, 2008 6:11 pm
by 0perand
Ok so I have a computer that is hooked to a network via ethernet cable. I have the same computer hooked to a DIFFERENT network via wireless. They have different ip addresses, default gateways and dns.

The ethernet nic has a static ip with no default gateway. It has a static DNS server.

IP: 192.168.100.200
SUBNET: 255.555.255.0
DNS: 192.168.100.251

The wireless nic is completely dynamic.

IP: 192.168.1.14
SUBNET: 255.255.255.0
DG: 192.168.1.1
DNS: 192.168.1.1

Now the problem is when I create a socket and send information out it always chooses the ethernet nic. If I disable the ethernet nic it works fine with the wireless. Is it possible to distinguish nics or do I have to configure something in the php.ini? Maybe something else...?

Thanks ahead of time, OP!

Re: Multiple NICs question

Posted: Thu Oct 16, 2008 9:32 pm
by Stryks
Just a quick question ... is the wireless router connected to the same wired network that you are plugged into? More to the point, do both the wired and wireless networks you are connected to have individual internet access? Is the IP address you are connecting to private or public (local or internet)?

It's just that, assuming that you are running php and webserver on your machine, it will use the same default route to the internet that the rest of your applications will. Without port forwarding or some other alternative, you can't use two connections to the internet simultaneously. Your network configuration will find the first route and use it for everything. The exception would be port forwarding, where you could, for example, specify port 80 be forwarded to the wireless dns, and the rest to the wired, forcing browser traffic through one network and everything else through another.

Now, if you're sending to an internal IP via the wired connection and accessing the internet via the wireless, well, that's a different matter. But then you shouldn't be in this situation.

At least, that's my understanding. Happy to stand corrected though.

Re: Multiple NICs question

Posted: Thu Oct 16, 2008 10:27 pm
by 0perand
No they are SEPERATE networks. The default gateway determines the DEFAULT ROUTE. If one nic has a default gateway then that is the default connection for internet. PHP does not use this nic it shows the ethernet nic.

I am posting from another computer. This computer is connected to the ethernet network and has the appropriate default gateway info. The WAN IP is : 66.91.250.90.

Now from the other computer when I go to whatsmyipaddress.com, it shows: 75.80.170.35. Hence the default gateway and default route are set to the wireless nic.

The php server is hosted locally on that computer. When I pull up $_SERVER[REMOTE_ADDR] it brings up 127.0.0.1.

I hope this clears up the situation.

Re: Multiple NICs question

Posted: Sat Oct 18, 2008 1:02 pm
by 0perand
Just in case anyone is interested, this is my solution... Its not pretty, but it does work.

Code: Select all

 
$Current_IP = $_SERVER['REMOTE_ADDR'];
 
//this fixes the localhost issues with ip6
if($Current_IP == "::1" || $Current_IP == '127.0.0.1')
{
    $Current_IP = '0.0.0.0';
}
//gets the computer name
$hostname = gethostbyaddr($Current_IP);
//stores a list of ips associated with the computer name in an array
$hosts = gethostbynamel($hostname);
 
var_dump($hosts);
 
This prints out:
array(2) { [0]=> string(14) "192.168.1.100" [1]=> string(14) "192.168.100.200"}