1
votes

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):

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
1

1 Answers

0
votes

It's possible to add multiple external static IP addresses to a VM instance. Each VM instance can have up to eight network interfaces and you can assign a static external IP to the added interfaces. However, is not possible to add the same NIC more than one to the same VM Instance and each added NIC subnetwork IP ranges cannot be overlapped. Each internal IP range got to be different1.

You may consider using a VM-appliance2 with multiple external IP addresses, useful for traffic separation as you intend to do.