GCP instance IP forwarding enabled

Allow IP forwarding only on VMs that require routing.

Description

can_ip_forward lets a VM send or receive packets whose source or destination IP is not assigned to it. Reserve it for VMs that serve as routers or network appliances.

Potential impact

If guest routing and firewall rules allow forwarding, a compromised VM can relay traffic to other networks.

Remediation

Before setting can_ip_forward = false on an application VM, check whether any route uses it as the next hop. Apply the change and test required connections. For an appliance that must forward packets, document its role and restrict guest forwarding, routes and firewall rules to approved traffic.

Examples

The examples change only the forwarding setting on the same VM. Use your project, zone, supported image and VPC. Control application-level proxies separately.

Before

hcl
resource "google_compute_instance" "appserver" {
  name           = "primary-application-server"
  machine_type   = "e2-medium"
  can_ip_forward = true

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-11"
    }
  }

  network_interface {
    network = "default"
  }
}

After

hcl
resource "google_compute_instance" "appserver" {
  name           = "primary-application-server"
  machine_type   = "e2-medium"
  can_ip_forward = false

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-11"
    }
  }

  network_interface {
    network = "default"
  }
}

References