Protocol forwarding overview (original) (raw)

Protocol forwarding uses a regional forwarding rule to deliver packets of a specific protocol to a single virtual machine (VM) instance. The forwarding rule can have an internal or an external IP address. Protocol forwarding delivers packets while preserving the destination IP address of the forwarding rule. The forwarding rule references an object called a target instance, which, in turn, references a single VM instance.

You can use protocol forwarding to do the following:

Protocol forwarding is different from a pass-through load balancer in the following ways:

Architecture

Protocol forwarding uses regional external or regional internal forwarding rules and a zonal target instance object. The target instance and the VM it references must be located in a zone in the forwarding rule's region.

Forwarding rules

Each forwarding rule matches an IP address, protocol, and optionally, port information (if specified and if the protocol supports ports). When a forwarding rule references a target instance, Google Cloud routes packets that match the forwarding rule's address, protocol, and port specification to the VM referenced by the target instance.

Keep the following points in mind when working with forwarding rules:

Target instances

A target instance is a zonal resource that references one VM instance in the same zone. The forwarding rule that references the target instance must be in the region containing the target instance's zone. Because a target instance doesn't have a Cloud NAT policy applied to it, it can be used for IPsec traffic that can't traverse NAT.

Multi-NIC support

Protocol forwarding using target instances supports VM instances with non-nic0 network interfaces (vNICs or Dynamic Network Interfaces) by using the --network flag when you create the target instance:

IPv6 support for VM instances

If you want the protocol forwarding deployment to support IPv6 traffic, the VM instance must be configured in either adual-stack or asingle-stack IPv6-only subnet that is in the same region as the IPv6 forwarding rule.

Note that while IPv6-only instances can be created in both dual-stack and IPv6-only subnets, dual-stack VMs can't be created in IPv6-only subnets.

The VM instance can be created in a subnet with the ipv6-access-type set to either EXTERNAL or INTERNAL. The VM inherits the ipv6-access-type setting (either EXTERNAL or INTERNAL) from the subnet.

For instructions, see Create an instance that uses IPv6 addresses. If you want to use an existing VM, you can update the VM to be dual-stack by using the gcloud compute instances network-interfaces updatecommand. Updating existing VMs to IPv6-only isn't supported.

IP addresses for request and return packets

When a target instance receives a packet from a client, the request packet's source and destination IP addresses are as shown in this table.

Table 1. Source and destination IP addresses for request packets

Protocol forwarding type Source IP address Destination IP address
External protocol forwarding The external IP address associated with a Google Cloud VM or an external IP address of a client on the internet. The IP address of the forwarding rule.
Internal protocol forwarding A client's internal IP address; for Google Cloud clients, the primary internal IPv4 address or IPv6 address or an IPv4 address from an alias IP range of a VM's network interface. The IP address of the forwarding rule.

Software running on the target instance VMs should be configured to do the following:

Return packets are sent directly from the target instance to the client. The response packet's source and destination IP addresses depend on the protocol:

The following table summarizes sources and destinations for return packets:

Table 2. Source and destination IP addresses for return packets

Traffic type Source IP address Destination IP address
TCP The IP address of the forwarding rule. The request packet's source IP address.
AH, ESP, GRE, ICMP, ICMPv6, and UDP For most use cases, the IP address of the forwarding rule.1 The request packet's source IP address.

1 With internal protocol forwarding, it is possible to set the response packet's source to the VM NIC's primary internal IPv4 address or IPv6 address or an alias IP address range. If a VM has IP forwarding enabled, it can use an arbitrary source IP address for packets that it sends to destinations routed within a VPC network. Not using the forwarding rule's IP address as a source is an advanced scenario because the client receives a response packet from an internal IP address that does not match the IP address to which it sent a request packet.

Outbound internet connectivity from target instances

VM instances referenced by target instances can initiate connections to the internet by using the IP address of the associated forwarding rule as the source IP address of the outbound connection.

Generally, a VM instance always uses its own external IP address or Cloud NAT to initiate connections. You use the forwarding rule IP address to initiate connections from target instances only in special scenarios such as when you need VM instances to originate and receive connections at the same external IP address.

Outbound packets sent from target instance VMs directly to the internet have no restrictions on traffic protocols and ports. Even if an outbound packet is using the forwarding rule's IP address as the source, the packet's protocol and source port don't have to match the forwarding rule's protocol and port specification. However, inbound response packets must match the forwarding rule IP address, protocol, and destination port of the forwarding rule. For more information, see Paths for regional external passthrough Network Load Balancers and external protocol forwarding.

This path to internet connectivity from a target instance VM is the default intended behavior according to Google Cloud's implied firewall rules. However, if you have security concerns about leaving this path open, you can use targeted egress firewall rules to block unsolicited outbound traffic to the internet.

Limitations

API and gcloud reference

For forwarding rules, see the following:

For target instances, see the following:

Pricing

For pricing information, see Network pricing: Cloud Load Balancing.

Quotas and limits

For the quotas on forwarding rules for protocol forwarding, see Quotas and limits: Forwarding rules.

What's next