Same server, same program, but started once using one network card and then another

I have a Linux server with multiple ips (so, multiple eth0, eth0: 0, eth0: 1, etc.). script I am trying to run a php CLI script that loads stuff from a different server API and I would like to change the IP based on different parameters. After running the script, I no longer need to change the ip OF THAT SPECIFIC script until the very end.

Do you have any hints if possible? My other solution was to install Xen or OpenVZ and create N different VPS for each IP, but as you can see, this is definitely PITA :-)

0


source to share


2 answers


You don't specify how you are connecting to another server, but with sockets, you can try socket_bind .



EDIT: With curl, you can try curl_setopt . CURLOPT_INTERFACE The name of the outgoing network interface to use. This can be an interface name, IP address, or hostname.

+2


source


I know how to do this in C - you use bind () on your socket before you call connect () and bind to the IP address assigned to the desired interface, passing 0 for the port. I don't know how to do this in PHP.



0


source







All Articles