I want to have a VM with multiple internal IPs each with a one-to-one relation to external IP address on a single network interface. I need to be able to initiate requests from that VM (single process) but need that different requests use different external IPs.
E.g.
10.146.0.3 <> 35.215.6.3
10.146.0.4 <> 35.215.6.6
10.146.0.5 <> 35.215.6.8
I managed to add multiple IPs to a single interface using alias IP ranges but can't find a way to map those extra internal IPs to external IPs. This can be done quite to be easily done on AWS (took me about 5-10 minutes) as shown here, but after two full days looking around, I still can’t find a way to do this at GCP.
I am not looking for load balancing functionality or for any inbound connection related functionally (my VM acts as an HTTP client, not a server, so I only care about outbound connections). Also, if possible I also want to avoid multiple network interfaces as they are limited by 1 per vCPU and therefore don’t scale well cost-wise (plus all the hassle of having to create new VPCs).
Related questions (which don't quite solve my problem):
- How do I setup 1 to 1 NAT in google cloud?
- Multiple IP addresses on a single Google Compute Engine instance
- How to assign multiple outgoing IPs addresses to a single instance on GCE?
For testing, I am using the following command:
curl -w '\n%{local_ip}\n' --interface <internal_ip> ifconfig.co
Which returns the external IP followed by the internal IP:
52.196.168.76
172.31.24.253