Gili
Gili

Reputation: 90053

How to assign multiple outgoing IPs addresses to a single instance on GCE?

How does one assign multiple ephemeral external IP addresses to the same machine on Google Compute Engine? The web interface only discusses the primary IP addresses, but I see no mention of adding more addresses.

I found a related question over at https://stackoverflow.com/a/39963576/14731 but it focuses on routing multiple incoming IPs to the same instance.

My application is a web client that needs to make multiple outgoing connections from multiple source IPs.

Upvotes: 2

Views: 402

Answers (1)

Yann Coleu
Yann Coleu

Reputation: 1426

Yes it's possible, with some steps:

  1. Create the same number of VPC (Network) as you need interfaces
  2. Create a subnet inside each VPC and make sure the are not overlapping
  3. Add a firewall rule in the first VPC to allow SSH from your location
  4. Create an instance with multiple interfaces (one in each VPC) and assign external address to each one
  5. SSH to your instance via the address located on the first VPC
  6. Configure a separate routing table for each network interface

Things you have to know:

  • You can add interfaces only on instance creation
  • I've got an error on configuration of routing table, but it worked (RTNETLINK answers: File exists)
  • Routing table of secondary interfaces are not persisted, you have to manage how to do this

Results

yann@test-multiple-ip:~$ ip a
[...]
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 42:01:c0:a8:00:02 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.2/32 brd 192.168.0.2 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::4001:c0ff:fea8:2/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 42:01:c0:a8:01:02 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.2/32 brd 192.168.1.2 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::4001:c0ff:fea8:102/64 scope link 
       valid_lft forever preferred_lft forever

yann@test-multiple-ip:~$ curl --interface eth0 ifconfig.co
35.241.195.172
yann@test-multiple-ip:~$ curl --interface eth1 ifconfig.co
35.241.253.41

Upvotes: 1

Related Questions