0

I need to assign different IP addresses to different processes (mostly PHP & Ruby programs) running on my Linux server. They will be making queries to various servers, including the situation where processes connecting to the same external server should have different IPs.

How this can be achieved?

Any option (system wide, or PHP/Ruby-specific, using proxy servers etc) will suit me.

3 Answers 3

2

A few choices:

  • Most easy one probably: NAT rule in POSTROUTING with the "owner" iptables module. If you run each process with its own username, you could have rules for each user to go out with a specific IP.
  • Run each process inside a container such as LXC or Virtuozzo.
  • Create a connection wrapper script for your applications to bind to an IP each and every connection.
2
  • Could you please explain the last option?
    – simon
    Jul 13, 2014 at 15:51
  • That's the most complicated one. It HIGHLY depends on your applications and what libraries you are using and so on. Jul 13, 2014 at 15:58
1

You also can use network namespaces, if kernel allows. like described here http://blog.scottlowe.org/2013/09/04/introducing-linux-network-namespaces/

0

Finally I solved my specific case with running nginx as reverse proxy, available from localhost only, using proxy_bind directive.

From my scripts I should make queries to something like http://localhost/nginx-proxy-ip-N/https://api.example.com/?q=123

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .