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.
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.
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:
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.
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)
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
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With