'Azure VM/Services - Using multiple outbound public IP randomly

My scenario:

I would like to setup a HTTP proxy server in a Linux VM using node.js.

It will only accept whitelisted inbound traffic, and route it to external services.

I assigned 4 public IP to the VM NIC as 4 different IP configurations.

However, all outbound traffic from this VM still uses the primary IP, never uses the other 3.

How do I route outbound traffic to each IP randomly/round robin?

I am also open is using other OS/Services to achieve this goal.

Thank you!



Solution 1:[1]

I found this to work.

const rndInt = Math.floor(Math.random() * 4) + 1
if (rndInt == 1) text = 1;
if (rndInt == 2) text = 2;
if (rndInt == 3) text = 3;
if (rndInt == 4) text = 4; 
    alert(text);

Example on a website using tags - https://altify-chs.netlify.app/html/proxychoose

Solution 2:[2]

Generally operating systems wont load balance between multiple outbound IP's as they select the "best" IP to send your traffic with.

Your application will need to bind all 4 IP's and randomize what IP is used for outbound requests.

Solution 3:[3]

Spent a bit more time today and found that the best solution for me is to setup a NAT gateway in the same subnet of the VM.

Then bind multiple public IPs to this NAT Gateway. Then outbound access from the VM uses these public IPs randomly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Altify
Solution 2 Nisd
Solution 3 Tony