skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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

    • Turn off the current machine
    • Detach disk and network (without deleting them !!!)
    • Create a new machine with 2 network cards or more
    • Attach the old disk and network to the new machine

    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

    ip addr add 10.130.0.2/32 broadcast 10.130.0.2 dev eth1
    ip link set eth1 up
    ip route add 10.130.0.1 src 10.130.0.2 dev eth1
    ip route add 10.130.0.1 src 10.130.0.2 dev eth1 table 100
    ip route add default via 10.130.0.1 dev eth1 metric 10
    ip route add default via 10.130.0.1 dev eth1 table 100
    ip rule add from 10.130.0.2/32 table 100
    ip rule add to 10.130.0.2/32 table 100
    curl --interface eth1 ifconfig.co
    curl --interface eth0 ifconfig.co
    ping -I eth1 8.8.8.8
    

    Here is the documentation, alternatively this guide may help.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search