Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple IP addresses on a single Google Compute Engine instance

I'm trying to have my GCE instance listen on multiple IP addresses (for SEO reasons - to host multiple low traffic sites on the same instance).

Final objective: mydomain.com points to IP1, myotherdomain.es points to IP2, the GCE instance will listen on both IP1 and IP2 and serve content accordingly.

I added a target instance pointing to my main instance and managed to create a forwarding rule like this:

gcloud compute forwarding-rules create another-ip --port 80 --target-instance MY_TARGET_INSTANCE_URL

It actually created an ephemeral IP address; I tried to promote it to static but I exceeded my quota (I'm currently on my 2 months free trial).

Is this correct though? Will I be able to create any number of static IPs and point them to my only instance once the trial ends? I also couldn't find anything about pricing: I know an IP assigned to an active instance is free, but what about additional ones?

Since this is a necessary configuration for a site I'm managing, I'd like to be sure it works before committing to moving everything on GCE.

like image 927
koichirose Avatar asked Oct 10 '16 16:10

koichirose


People also ask

Can a VM have multiple IP addresses?

Any NIC can have one or more static or dynamic public and private IP addresses assigned to it. Assigning multiple IP addresses to a VM enables the following capabilities: Hosting multiple websites or services with different IP addresses and TLS/SSL certificates on a single server.

What is the minimum number of IP addresses that a VM instance needs?

Each VM instance network interface must have one primary internal IPv4 address. Each network interface can also have one or more alias IPv4 ranges, and one external IPv4 address. If the VM is connected to a subnet that supports IPv6, each network interface can also have internal or external IPv6 addresses assigned.

Why does Google have multiple IP?

The many Google IP addresses support searches and other internet services such as the company's DNS servers. ​Like many popular websites, Google uses many servers to handle incoming requests to its website and services.


2 Answers

You can get multiple external IPs for one VM instance with forwarding rules.

  1. By default, VM will be assigned with an ephemeral external IP, you can promote it to static external IP, which will remain unchanged after stop and restart.
  2. Extra external IPs have to be attached to forwarding rules which point to the VM. You can use (or promote to) static IPs as well.

The command you may want to use:

  1. Create a TargetInstance for your VM instance:

    gcloud compute target-instances create <target-instance-name> --instance <instance-name> --zone=<zone>
    
  2. Create a ForwardingRule pointing to the TargetInstance:

    gcloud compute forwarding-rules create <forwarding-rule-name> --target-instance=<target-instance-name> --ip-protocol=TCP --ports=<ports>
    

See Protocol Forwarding.

like image 139
Dagang Avatar answered Sep 27 '22 17:09

Dagang


I am also need 2 static ips for one compute engine instance but google's quota is not allow this.

You can see your quotas from https://console.cloud.google.com/iam-admin/quotas

enter image description here

like image 26
Savas Adar Avatar answered Sep 27 '22 18:09

Savas Adar