Dynamic outgoing IP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
johndoe11
Forum Newbie
Posts: 3
Joined: Mon Sep 12, 2005 11:17 pm

Dynamic outgoing IP?

Post by johndoe11 »

Hi,

I'd like to know how to dynamically change the outgoing IP of a script connecting to external servers. Below is the scenario:

I have a script in server ABC with main IP address 12.12.12.12. This server also has other IPs mapped to it, 23.23.23.23 and 34.34.34.34. This script will access say a web script on server DEF. Now the web script on DEF will see my connecting script as originating from IP 12.12.12.12.

How do I dynamically configure my script so that when it accesses the web script on DEF, that remote script sees my script's originating IP as 23.23.23.23 or 34.34.34.34? I only know of one way, which is to actually alter the server's main IP address and restart the system, but that is not dynamic at all, and all scripts would then end up using that one particular IP again.

Please advise, thanks.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

The easiest is to configure the virtualhost def in your httpd.conf to bind with multiple ips...

An example, i can surf to http://test and for me that is 127.0.0.1 and for others that is 192.168.1.11

Code: Select all

NameVirtualhost *:80


<VirtualHost *:80>
  ServerName test
  DocumentRoot "F:/websites/test"
  <Directory "F:/websites/test">
    AllowOverride All
    Options All
  </Directory>
</Virtualhost>
johndoe11
Forum Newbie
Posts: 3
Joined: Mon Sep 12, 2005 11:17 pm

Post by johndoe11 »

Thanks for your reply. Sorry, maybe I didn't describe my problem well.

I didn't mean how to access a particular website / apache through different IPs. I understand that that can be achieved through binding multiple IPs to apache.

What I actually meant was how the originating script run at Server ABC is detected to be coming from a different IP other than the default IP assigned to that server. Maybe I can illustrate it better with a simple diagram:

Server ABC
==========
IP: 12.12.12.12
Other IPs mapped:
23.23.23.23
34.34.34.34
Contains: Script A

Server DEF
===================
IP: 89.89.89.89
Contains: Script B


Script A connects to =======> Script B (either through http or some internal socket connection)


In this scenario, Script B detects that Script A's IP is 12.12.12.12. How do I configure PHP or Server ABC so that Script A can utilize an outgoing IP of 23.23.23.23 or 34.34.34.34, without actually modifying the network configuration of Server ABC's server IP to something else?

This is probably like IP spoofing, except that it is not really a spoof as it is using another valid IP mapped to the server. Please advise, thanks.
johndoe11
Forum Newbie
Posts: 3
Joined: Mon Sep 12, 2005 11:17 pm

Post by johndoe11 »

Hmm.... I think I figured out how...

curl_setopt($ch, CURLOPT_INTERFACE, "SOME IP ADDRESS");

Do you know how to do it without using curl?


Thanks a lot.
Post Reply