How to run multiple node.js scripts from different IP? - node.js

I have one Debian server that has 2 different IP address.
How to run two copies of my NodeJS script from different IP address?

I found a solution:
http.request() and request() has localAddress option. Set it to IP what you need and use.

Related

Docker container with multiple outgoing IPs

I have an application written in node js which is using multiple outgoing IPs to make requests to website. Basically, I want to make requests to some website with different IPs, which I have assigned to my VPS. I want to containerize my application with docker, but docker only has access to the main IP from the host machine and I was not able to assign my other IPs to that container. I've tried many things and been stuck on that problem for days...
IPv4 address for enp1s0: xxx.xx.xxx.70
IPv4 address for enp1s0: xxx.xxx.x.145
IPv4 address for enp1s0: xxx.xxx.xxx.154
I need to be able to select one of these IPs from node js application inside docker container and me an HTTP request with it.
Also if what I said is not possible it is also acceptable to assign each IP to each container (so 3 containers in total with different outgoing IPs). But this is not ideal. I'm looking for a painless way of doing this since I want to be able to pre-configure my apps and docker-compose to automate most of this work.

how to create ip alias in nodejs

I am writing test in nodejs.
Calling my api using requestjs.
Now I have to make one call using an ip address to the api (/resources/media)
Then I have to make another call to the same api (/resources/media) using different ip from the same computer.
OS: ubuntu
any idea how to do that
help is very much appreciated.
Thanks
Your only choice is to set up a proxy (like squid), bind it to another (virtual) networking interface card and make the second request through it.
add another ip and make sure it was not existed before
sudo ip addr add 192.168.50.5 dev eth1
Then user localAddress option in requestjs

How to forward incoming clients based on ip to a specific process

I have a server that has multiple ip addresses. It also has multiple web apps written in nodejs that I'm running.
In short I'd like to forward specific ip addresses to specific node applications. How is this done? Should I use apache or nginx?
running centos 7
Any running application can bind to either 0.0.0.0 (to catch all the packets) or to some specific IP (it must use this ip when it calls bind() on the socket). Thus almost any TCP/IP server application has option like "Listen" in it's config file or command line, so you should read your docs carefully to figure out how can it be made in your particular application. For Apache it's port-based virtual hosts.
If you want to route user requests to different application based on user's IP address, you should read about iptables nat table and REDIRECT target.

How to use multiple IPs for different browser tabs/programs in an AWS ec2 instance?

So when I purchase a AWS ec2 large instance I want to do the following:
Use a linux AMI
Install for example Gnome so I can view it like a GUI
Install a browser
Open multiple different browsers/tabs
When I go to a whatismyip.com I want it to show a different IP address in each tab/browser
So is there a function or possibility to right click a program and say like "connect to the internet using ... IP address"?
I want to use the built in IP addresses provided by Amazon, elastic IP adresses.
Maybe you could use different proxies from different browser instances. Proxy setup should then be in a way that different IP adresses are used.
If you're willing to forgo a browser the tor project has an api which will let you leverage its routing capabilities programatically.
You have to use proxy for each browser, for each tab is not allowed.
Once you have 3 valid transparent proxies (preferable SOCKS 4/5) you will have 3 unique IP addresses.

Same server, same program but started once using one network card and after with another

I have a Linux server with multiple ips (so, multiple eth0, eth0:0, eth0:1 etc).
The script I'm trying to start is a php CLI script which is downloading stuff from an another server API, and I would like to change the IP based on different parameters. Once the script is started, I don't need anymore to change the ip OF THAT SPECIFIC script until his end.
Do you have any clue if it is possible to achieve it?
My other solution was to install Xen or OpenVZ and create N different VPS per each IP, but as you can see is definitely a PITA :-)
You don't specify how you connect to the other server, but with sockets you can try socket_bind.
EDIT:
With curl you can try curl_setopt.
CURLOPT_INTERFACE The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name.
I know how to do it in C - you use bind() on your socket before you call connect(), and you bind to the IP address assigned to the desired interface, passing 0 for port. I don't know how to do it in PHP.

Resources