Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding ip with forwarding rules in google cloud

Can anyone provide a tutorial on how I could add additional IP to my instance via forwarding in google cloud?

The current documentation is too complicated and not helpful. It does not state where the command should be executed and instruction is too vague.

I've been trying to setup a new instance, but I could not understand how I could setup the forwarding of all traffic on this instance to other instance. I would highly appreciate if someone could shine a light on this topic.

thank you.

like image 415
James Tan Avatar asked Dec 16 '14 10:12

James Tan


People also ask

Which types of external IP addresses are supported by forwarding rule in Google compute engine?

Forwarding rules for target pool-based network load balancer support only IPv4 addresses. For regional external IPv4 addresses, the Network Load Balancing supports both Standard Tier and Premium Tier. Regional external IPv6 addresses are only available in the Premium Tier.


1 Answers

I understood your question differently (compared to the other answer). I understand you need a second public IP pointing to an instance that already has its own public IP. If that is the case, follow these steps:

  1. Let's start with the SDK, since you mention:

    It does not states where the command should be executed and instruction is too vague

The commands are executed in your terminal once you have downloaded and installed Google Cloud SDK. In Linux/OS X it would be:

    curl https://sdk.cloud.google.com | bash

There's a 3-step guide in that link with more information.

  1. Issue the command:

    gcloud compute instances list
    

to get a list of your instances and the zone they belong to. Take note of the NAME and the ZONE of the instance you need to work with. Notice the REGION needed in the commands below, is the first part of the ZONE field. (For example: ZONE: us-central1-f, then REGION is us-central1)

  1. Create a static public IP to receive the traffic you want to forward:

    gcloud compute addresses create NAME
    gcloud compute addresses create targ-ip-1
    

where NAME is again, of your choice. It will prompt for the region (pick the same region where your instance is). This command will return an IP, let's say: W.X.Y.Z

  1. You then need to create a target-instance:

    gcloud compute target-instances create NAME --instance INSTANCE
    gcloud compute target-instances create targ-ins-1 --instance instance-1
    

where NAME is a name of your choice for the target instance. INSTANCE is the name of the instance which will be handling traffic from one or more forwarding rules. It will prompt for the zone (pick the same zone where your instance is).

You can also create target-pools to point to several instances at the same time, instead of just a target instance.

  1. Create the forwarding rule, using the target instance and the static public IP you just created:

    gcloud compute forwarding-rules create NAME --address ADDRESS --target-instance TARGET_INSTANCE --target-instance-zone TARGET_INSTANCE_ZONE --ip-protocol IP_PROTOCOL --port-range [PORT | PORT-PORT]
    gcloud compute forwarding-rules create fwd-rule-1 --address W.X.Y.Z --target-instance targ-ins-1 --target-instance-zone us-central1-f --ip-protocol TCP --port-range 5678-5680
    

where:

  • NAME: a name of your choice for the forwarding rule
  • ADDRESS: the IP address you reserved in step 3
  • TARGET_INSTANCE: the target instance name you created in step 4
  • TARGET_INSTANCE_ZONE: the zone where your target instance belongs to
  • IP_PROTOCOL (optional): The IP protocol that the rule will serve. If left empty, TCP is used. Supported protocols are: AH, ESP, SCTP, TCP, UDP.
  • PORT (optional): If specified, only packets addressed to ports in the specified range will be forwarded. If not specified, all ports are matched

You will be prompted to select a region where this rule will belong to.

To verify your rule, you can list your configured forwarding rules like this:

gcloud compute forwarding-rules list

You should start receiving traffic pointing to the new public IP, in the instance you chose.

like image 85
maganap Avatar answered Sep 24 '22 15:09

maganap