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.
3
Answers
You can get multiple external IPs for one VM instance with forwarding rules.
The command you may want to use:
Create a TargetInstance for your VM instance:
Create a ForwardingRule pointing to the TargetInstance:
See Protocol Forwarding.
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
An other possibility is to have multiple network interface on the VM
This require adding a new VPC network, the ip 10.130.0.0/20 is not used on the current infrastructure and can be used as an additional network, you would add the proper firewall rules and the proper routing rules (you can copy the default one to avoid any miss-configuration)
Note that you can not add a network interface to an existing machine, you would need to
Finally you would need to pay attention to the default gateway, the classic network behavior would make everything go through the first network interface the second won’t be accessible until you change the default gateway and or create the proper routing rules.
Typically you have eth0 and eth1 this example makes eth1 available to services that bind to eth1
Here is the documentation, alternatively this guide may help.