1

I have set a dedicated IP for a website (using directadmin), but all outgoing php requests are sent from the server's shared IP. Result of the following code is always the shared IP.

$a = file_get_contents("http://mxtoolbox.com/WhatIsMyIP/");
print $a;

I need to send requests from dedicated IP because my payment gateway only accepts requests from that IP.

Do I need to add iptables rules to send all requests from the dedicated IP or there is a better way?

Devon
  • 800
  • 1
  • 9
  • 20
hpn
  • 165
  • 2
  • 6
  • 1
    [Administration panels are off topic](http://serverfault.com/help/on-topic). [Even the presence of an administration panel on a system,](http://meta.serverfault.com/q/6538/118258) because they [take over the systems in strange and non-standard ways, making it difficult or even impossible for actual system administrators to manage the servers normally](http://meta.serverfault.com/a/3924/118258), and tend to indicate low-quality questions from *users* with insufficient knowledge for this site. – HopelessN00b Mar 23 '15 at 15:16

2 Answers2

4

Set a route to the payment processor via the dedicated IP. The ip route add command is your friend.

user9517
  • 115,471
  • 20
  • 215
  • 297
1

This should be at StackOverflow. You need to create a context for your socket.

$opts = array(
    'socket' => array(
        'bindto' => '10.10.1.1:0',
    )
);

$context = stream_context_create($opts);
$a = file_get_contents("http://mxtoolbox.com/WhatIsMyIP/", false, $context);
print $a;

In this example, this will bind to IP 10.10.1.1. Port 0 is used to allow the OS to choose the port.

Otherwise, you'll have to either change your default route for all traffic or determine the IP address of the site you are trying to reach. The latter of which can be unreliable if they use a distributed network or change their address.

Devon
  • 800
  • 1
  • 9
  • 20
  • 1
    The user did not _ask_ for a programming solution. Your answer might be appropriate for SO, but it is not here. – Michael Hampton Feb 13 '15 at 19:07
  • 1
    @MichaelHampton yes but he gave PHP code and assuming he isn't the root user or doesn't want to change the default route, there is no other reliable way as per my last point. – Devon Feb 13 '15 at 20:29
  • You're making an inappropriate assumption. Someone asking a question on [sf] almost always _is_ root and can change system routes. (If they aren't, then they shouldn't be asking questions here to begin with.) – Michael Hampton Feb 13 '15 at 20:50
  • ....and what happens when you bind the socket to an interface which doesn't have a route to the destination? – symcbean Feb 14 '15 at 01:06
  • @symcbean: I suspect the same thing as if you added a faulty route in the routing tables... – Devon Feb 14 '15 at 01:27
  • I on the other hand was looking for a programming solution. – Steven Linn Jun 18 '15 at 14:18