tags:

views:

75

answers:

1

I’ve got ethernet interface on FreeBSD 7.1 with 3 ip adresses binded to it.

# ifconfig

em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=19b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4>
ether 00:e0:81:b1:1b:4b
inet 89.xx.xx.1 netmask 0xfffffc00 broadcast 89.xx.xx.255
inet 89.xx.xx.2 netmask 0xffffffff broadcast 89.xx.xx.2
inet 89.xx.xx.3 netmask 0xffffffff broadcast 89.xx.xx.3
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active

How to launch php script binded to different ip adresses? I need this script to access one service from different ip addresses.

+1  A: 

If you want to set up a service at a specified IP-address, just fill in that address as the second parameter of the socket_bind function. If the IP address is varying depending on the situation, you can use a command line parameter to specify this address

If you want the script to use a specified IP address when connecting to a remote service, that is not easy. Since the internet stack on your computer determines which IP address will be used, depending on which network the destination is. And in your case all IP addresses are on the same network.
I think that you you should think in this situation whether it is really required to use a particular address...

Veger
Binding to specific IP is very easy when connecting to a remote server. In case of the socket_* functions, you just need to call socket_bind before doing socket_connect (yes, socket_bind is not just for listening sockets). In case of HTTP stream wrappers and such (such as file_get_contents), they accept a context parameter which you can use to setup a context that binds to a specific IP address (see: http://fi.php.net/manual/en/context.socket.php)
reko_t
Also curl_setopt may be used.$ch = curl_init();curl_setopt($ch, CURLOPT_INTERFACE, "XXX.XXX.XXX.XXX");
SaltLake