3

I am trying to turn on IP Forwarding for an interface of an instance hosted in Google Cloud.

  1. I have a f1 micro VM instance on Google Compute Engine.
  2. I've created an IP forwarding rule with gcloud succesfuly here.
    Command compute forwarding-rules describe myrulenamehere gives out description of the rule.
  3. When I open VM instance details page IP forwarding is marked as OFF and I can't change it via EDIT button.

How to turn on IP Forwarding for interface if forwarding rule was already created?

GalloCedrone
  • 371
  • 1
  • 9
ilyaigpetrov
  • 135
  • 1
  • 2
  • 8

3 Answers3

3

You cannot change this value since it is a read-only value for already created instances. From the official Google documentation that you can check here:

You can only set the canIpForward field at instance creation time. After an instance is created, the field becomes read-only.

Therefore I think that the only option you have now is to create again the virtual machine, the target instance and the forwarding rule. You can enable ip-forwarding at creation time with the flag --can-ip-forward, for example:

gcloud compute instances create instance-name --can-ip-forward

You can enabling it as well from the Console, in the Network interface menu, at the creation of the instance.

You can as well keep the very same forwarding rule and update the target instance only running:

gcloud compute forwarding-rules set-target ...
GalloCedrone
  • 371
  • 1
  • 9
0

GCP has added the option to update IP_FORWARDING withouth recreating the VM instance.

gcloud compute instances update-from-file INSTANCE_NAME

For more details check update-instance-properties.

Ivan
  • 186
  • 3
0

As @Ivan stated, GCP now allows for canIpForward to be set after creation. But if you are new to GCP its not intuitive how to do it from the cloud shell/terminal.

open the console then issue the following command:

gcloud compute instances export myInstanceName --project myProjectName --zone instanceZone --destination=instConfig.txt

The config file ends in the store for your shell instance, not your local work station (regardless of what the documentation says).

Click on the 3x vertical dots just above the terminal and click download. Unpack the zip file and locate instConfig.txt. Edit the attributes you want to change, save the file. Click the 3x vertical dots and then upload -> file -> browser -> upload.

once uploaded issue the following command:

gcloud compute instances update-from-file myInstanceName --project myProjectName --zone instanceZone --source=instConfig.txt --most-disruptive-allowed-action=REFRESH

Check the network interfaces for the instance: IP forwarding is now On