Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have configured eth0 with 8 IP also add proper virtualhost in apache for different IP and everything works almost fine. When the script (like PHP,ruby) lauched by apache2 try to make outgoing connection (through cURL) it uses default eth0:0 IP not one related to domain (and incoming request). I'm trying to use something similar to this

iptables -t nat -A POSTROUTING -s 192.168.1.202 -o eth0 -j SNAT --to 99.99.99.244
iptables -t nat -A POSTROUTING -s 192.168.1.202 -o eth0 -j SNAT --to 99.99.99.245
iptables -t nat -A POSTROUTING -s 192.168.1.202 -o eth0 -j SNAT --to 99.99.99.247
iptables -t nat -A POSTROUTING -s 192.168.1.202 -o eth0 -j SNAT --to 99.99.99.246
share|improve this question
    
You'll need to associate a different user which each virtual host and launch scripts as that user. Then you can use iptables rules to set the default source IP address. –  David Schwartz Nov 5 '12 at 12:44
add comment

2 Answers

up vote 3 down vote accepted

You can use the --interface switch to cURL to direct which interface it uses but you'll need to work out yourself which interface to use and pass it as a parameter from your script

--interface Perform an operation using a specified interface. You can enter interface name, IP address or host name. An example could look like:

          curl --interface eth0:1 http://www.netscape.com/

         If this option is used several times, the last one will be used.
share|improve this answer
add comment

This may be over complicating things a little. You need to change your routing table in a way more advanced than route can. Instead you can use the iproute2 suite of tools. This tool comes as standard with most main line distributions.

ip route change 0.0.0.0/0 dev eth0 src 1.2.3.4 via 1.2.3.1
          source address you want to use -^           ^
                                     default gateway -^
share|improve this answer
    
PS. Careful with the above command you are changing your default route and if its wrong you could lose connection to the server you're working on. –  James Park-Watt Nov 5 '12 at 13:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.