Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 -o eth0 -j SNAT --to
iptables -t nat -A POSTROUTING -s -o eth0 -j SNAT --to
iptables -t nat -A POSTROUTING -s -o eth0 -j SNAT --to
iptables -t nat -A POSTROUTING -s -o eth0 -j SNAT --to
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
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

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

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 dev eth0 src via
          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

Your Answer


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.