Forwarding rules overview (original) (raw)

A forwarding rule specifies how to route network traffic to the backend services of a load balancer. A forwarding rule includes an IP address, an IP protocol, and one or more ports on which the load balancer accepts traffic. Some Google Cloud load balancers limit you to a predefined set of ports, and others let you specify arbitrary ports.

A forwarding rule and its corresponding IP address represent the frontend configuration of a Google Cloud load balancer.

Depending on the load balancer type, the following is true:

In addition, global and regional forwarding rules can be designated as services in App Hub applications.

Internal forwarding rules

Internal forwarding rules forward traffic that originates inside a Google Cloud network. The clients can be in the same Virtual Private Cloud (VPC) network as the backends, or the clients can be in a connected network.

Internal forwarding rules are used by the following Google Cloud load balancers:

Internal Application Load Balancer

The internal Application Load Balancer supports IPv4 traffic using either the HTTP, HTTPS, or HTTP/2 protocols.

The scope of the forwarding rule depends on the type of load balancer:

Internal managed forwarding rules connected to a target HTTP(S) proxy support any port number between 1 and 65535 inclusive.

As an example, the following diagram shows how a forwarding rule fits into the regional internal Application Load Balancer architecture.

Regional internal Application Load Balancer forwarding rule.

Regional internal Application Load Balancer forwarding rule (click to enlarge).

For more information about internal Application Load Balancers, see the following pages:

Internal proxy Network Load Balancer

With an internal proxy Network Load Balancer, the supported traffic type is IPv4, and the supported protocol is TCP.

The scope of the forwarding rule depends on the type of load balancer:

Internal managed forwarding rules connected to a target TCP proxy support any port number between 1 and 65535 inclusive.

The following diagram shows how a forwarding rule fits into the regional internal proxy Network Load Balancer architecture.

Regional internal proxy Network Load Balancer forwarding rule.

Regional internal proxy Network Load Balancer forwarding rule (click to enlarge).

For more details about internal proxy Network Load Balancers, see the following pages:

Internal passthrough Network Load Balancer

With an internal passthrough Network Load Balancer, the supported traffic types areeither IPv4 or IPv6. For information about the supported protocols, seeForwarding rule protocols.

Each internal passthrough Network Load Balancer has at least one regional internal forwarding rule. The regional internal forwarding rules point to the load balancer's regional internal backend service. The following diagram shows how a forwarding rule fits into the internal passthrough Network Load Balancer architecture.

Internal passthrough Network Load Balancer forwarding rule.

Internal passthrough Network Load Balancer forwarding rule (click to enlarge).

The following diagram shows how the load balancer components fit within a subnet and region.

The internal forwarding rule must be defined in a region and a subnet. The backend service only needs to correspond to that region.

High-level internal passthrough Network Load Balancer example.

High-level internal passthrough Network Load Balancer example (click to enlarge).

For more information about internal passthrough Network Load Balancers, see the following pages:

External forwarding rules

External forwarding rules accept traffic from client systems that have internet access, including:

External forwarding rules are used by the following Google Cloud load balancer types:

External Application Load Balancer

For external Application Load Balancers, the forwarding rule and IP address depend on theload balancer mode, and the Network Service Tiers that you select for the load balancer.

In an external Application Load Balancer, a forwarding rule points to a target HTTP(S) proxy. External forwarding rules connected to a target HTTP(S) proxy support any port number between 1 and 65535 inclusive.

IP address and forwarding rule requirements change depending on the Network Service Tier:

The following diagram shows how a global forwarding rule fits into the architecture for a global external Application Load Balancer. The same architecture also applies to the classic Application Load Balancer in Premium Tier.

Global external Application Load Balancer forwarding rule.

Global external Application Load Balancer forwarding rule (click to enlarge).

For more information about external Application Load Balancers, see theExternal Application Load Balancer overview.

External proxy Network Load Balancer

An external proxy Network Load Balancer offers TCP proxying capability, with optional SSL offload. An external proxy Network Load Balancer is similar to an external Application Load Balancer because it can terminate SSL (TLS) sessions. However, these load balancers don't support path-based redirection like external Application Load Balancers, so they're better suited for handling SSL for protocols other than HTTPS, such as IMAP or WebSockets over SSL. In an external proxy Network Load Balancer, a forwarding rule points to either a TCP or an SSL target proxy.

External proxy Network Load Balancers support both Premium Tier and Standard Tier. The forwarding rule and IP address depend on the type of load balancer mode and the Network Service Tiers that you select for the load balancer:

IP address and forwarding rule requirements change depending on the Network Service Tier:

External forwarding rules connected to a target TCP or SSL proxy support any port number between 1 and 65535 inclusive.

The following diagram shows how a forwarding rule fits into the global external proxy Network Load Balancer architecture.

Global external proxy Network Load Balancer forwarding rule.

Global external proxy Network Load Balancer forwarding rule (click to enlarge).

For more information about external proxy Network Load Balancers, see theExternal proxy Network Load Balancer overview. For information about configuring external proxy Network Load Balancers, seeSet up an external proxy Network Load Balancer.

External passthrough Network Load Balancer

External passthrough Network Load Balancers is a pass-through load balancer that distributes traffic among backend instances in a single region. An external passthrough Network Load Balancer uses a regional external forwarding rule and a regional external IP address. The regional external IP address can be accessed from anywhere on the internet and by Google Cloud VMs with internet access.

For backend service-based external passthrough Network Load Balancers, the regional external forwarding rule points to a backend service. Backend service-based external passthrough Network Load Balancers support TCP, UDP, ESP, GRE, ICMP, and ICMPv6 traffic. For details, see Forwarding rule protocols for backend service-based external passthrough Network Load Balancers. Forwarding rules for backend service-based load balancers can be configured with either IPv4 or IPv6 addresses. Forwarding rules for backend service-based external passthrough Network Load Balancers support the following advanced features:

For target pool-based external passthrough Network Load Balancers, the forwarding rule points to atarget pool. A target pool-based external passthrough Network Load Balancer supports only TCP or UDP traffic. Forwarding rules for target pool-based external passthrough Network Load Balancer support only IPv4 addresses.

For regional external IPv4 addresses, the external passthrough Network Load Balancer supports both Standard Tier and Premium Tier. Regional external IPv6 addresses are only available in the Premium Tier.

To support backend instances in more than one region, you must create a external passthrough Network Load Balancer in each region. This is the case regardless of whether the IP address of the load balancer is in the Premium Tier or the Standard Tier.

The following figure shows an external passthrough Network Load Balancer which has a regional external forwarding rule with the IP address, 120.1.1.1. The load balancer is serving requests from backends in the us-central1 region.

External passthrough Network Load Balancer example.

External passthrough Network Load Balancer example (click to enlarge).

For more information about external passthrough Network Load Balancers, see theExternal passthrough Network Load Balancer overview. For information about configuring external passthrough Network Load Balancers, see one of the following:

How Network Service Tiers affect load balancers

In Network Service Tiers, the distinction between Standard Tier and Premium Tier depends on how far traffic is routed over the public internet:

Load balancer Supported Network Service Tiers
Global external Application Load Balancer Global external proxy Network Load Balancer These load balancers are always Premium Tier. Their backend services, forwarding rules, and IP addresses are global.
Classic Application Load Balancer Classic proxy Network Load Balancer These load balancers can be Premium Tier or Standard Tier. With Premium Tier, they are global. Their forwarding rules, IP addresses, and backend services are global. In Standard Tier, these load balancers are effectively regional. Their backend services are global, but their forwarding rules and IP addresses are regional.
Regional external Application Load Balancer Regional external proxy Network Load Balancer These load balancers can be Premium or Standard Tier. Their backend services, forwarding rules, and IP addresses are always regional.
Cross-region internal Application Load Balancer Regional internal Application Load Balancer Regional internal proxy Network Load Balancer Cross-region internal proxy Network Load Balancer Internal passthrough Network Load Balancer These load balancers support traffic within a VPC network (including networks connected to it). Traffic is Premium Tier because it is within a VPC network.
External passthrough Network Load Balancer These load balancers must use regional external IPv4 or IPv6 addresses. These load balancers can be either Premium or Standard Tier. IPv6 addresses require Premium Tier. Only thebackend service-based external passthrough Network Load Balancers can handle IPv6 traffic.

IP protocol specifications

Each forwarding rule has an associated IP protocol that the rule will serve. The default protocol value is TCP.

Product Load balancing scheme IP protocol options
Global external Application Load Balancer EXTERNAL_MANAGED TCP
Classic Application Load Balancer EXTERNAL TCP
Regional external Application Load Balancer EXTERNAL_MANAGED TCP
Cross-region internal Application Load Balancer INTERNAL_MANAGED TCP
Regional internal Application Load Balancer INTERNAL_MANAGED TCP
Global external proxy Network Load Balancer EXTERNAL_MANAGED TCP or SSL
Classic proxy Network Load Balancer EXTERNAL TCP or SSL
Regional external proxy Network Load Balancer EXTERNAL_MANAGED TCP
Regional internal proxy Network Load Balancer INTERNAL_MANAGED TCP
Cross-region internal proxy Network Load Balancer INTERNAL_MANAGED TCP
External passthrough Network Load Balancer EXTERNAL TCP, UDP, orL3_DEFAULT
Internal passthrough Network Load Balancer INTERNAL TCP, UDP, or L3_DEFAULT
Cloud Service Mesh INTERNAL_SELF_MANAGED TCP

IP address specifications

The forwarding rule must have an IP address that your customers use to reach your load balancer. The IP address can be static or ephemeral.

A static IP address provides a single reserved IP address that you can point your domain to. If you ever need to delete your forwarding rule and re-add it, you can continue using the same reserved IP address.

An ephemeral IP address remains constant while the forwarding rule exists. When you choose an ephemeral IP address, Google Cloud associates an IP address with your load balancer's forwarding rule. If you need to delete the forwarding rule and re-add it, the forwarding rule might receive a new IP address.

Depending on the load balancer type, the IP address can have various attributes. The following table summarizes the valid IP address configurations, based on the load balancing scheme and the target of the forwarding rule.

Product and scheme Target IP address type IP address scope IP address tier Reservable IP address Notes
Global external Application Load Balancer EXTERNAL_MANAGED Target HTTP proxyTarget HTTPS proxy External Global Premium Tier: Global external IP address and forwarding rule Yes, optional IPv6 available
Classic Application Load Balancer EXTERNAL* Target HTTP proxy Target HTTPS proxy External Regional or global, matching the forwarding rule Premium Tier: Global external IPv4 or IPv6 address and forwarding ruleStandard Tier: Regional external IPv4 address and forwarding rule Yes, optional IPv6 available with a global external address (Premium Tier)
Regional external Application Load Balancer EXTERNAL_MANAGED Target HTTP proxyTarget HTTPS proxy External Regional Premium Tier or Standard Tier Yes, optional IPv6 not available
Cross-region internal Application Load Balancer INTERNAL_MANAGED Target HTTP proxyTarget HTTPS proxy Internal Regional Premium Tier Yes, optional Global forwarding rule is configured with a regional IP address within the primary IPv4 address range of the associated regional subnet. This is different from the global external Application Load Balancer where the global forwarding rule has a global anycast IP address.
Regional internal Application Load Balancer INTERNAL_MANAGED Target HTTP proxyTarget HTTPS proxy Internal Regional Premium Tier Yes, optional Forwarding rule address must be within the primary IPv4 address range of the associated subnet.
Global external proxy Network Load Balancer EXTERNAL_MANAGED Target SSL proxy Target TCP proxy External Global Premium Tier Yes, optional IPv6 available
Classic proxy Network Load Balancer EXTERNAL Target SSL proxy Target TCP proxy External Regional or global, matching the forwarding rule Premium Tier: Global external IPv4 or IPv6 address and forwarding ruleStandard Tier: Regional external IPv4 address and forwarding rule Yes, optional IPv6 available with a global external address (Premium Tier)
Regional external proxy Network Load Balancer EXTERNAL_MANAGED Target TCP proxy External Regional Premium Tier or Standard Tier Yes, optional IPv6 not available
Regional internal proxy Network Load Balancer INTERNAL_MANAGED Target TCP proxy Internal Regional Premium Tier Yes, optional Forwarding rule address must be within the primary IPv4 address range of the associated subnet
Cross-region internal proxy Network Load Balancer INTERNAL_MANAGED Target TCP proxy Internal Regional Premium Tier Yes, optional Forwarding rule address must be within the primary IPv4 address range of the associated subnet
External passthrough Network Load Balancer EXTERNAL Backend service Target pool External Regional Standard (IPv4 addresses) Premium (IPv4 or IPv6 addresses) Yes, optional IPv6 support requires a backend service-based external passthrough Network Load Balancer. Forwarding rule IPv6 address must be within a subnet's external IPv6 address range. The external IPv6 address is sourced from the subnet's external IPv6 address range and is therefore in Premium Tier.
Internal passthrough Network Load Balancer INTERNAL Backend service Internal Regional Premium Tier Yes, optional For IPv4 traffic, the forwarding rule must reference an IPv4 address from the primary IPv4 subnet range. For IPv6 traffic, the forwarding rule must reference a/96 range of internal IPv6 addresses from a dual-stack or single-stack (IPv6-only) subnet's /64 internal IPv6 address range.
Cloud Service Mesh INTERNAL_SELF_MANAGED Target HTTP proxyTarget gRPC proxy Internal Global Not applicable No 0.0.0.0, 127.0.0.1, or any RFC 1918 address is allowed
Classic VPN EXTERNAL See the Classic VPN documentation External Regional Cloud VPN doesn't have Network Service Tiers Yes, required IPv6 not supported

Multiple forwarding rules with a common IP address

Two or more forwarding rules with the EXTERNAL or EXTERNAL_MANAGED load balancing scheme (or a combination of both) can share the same IP address if the following are true:

Examples:

Two or more forwarding rules with the INTERNAL or INTERNAL_MANAGED load balancing scheme (or a combination of both) can share the same IP address if the following is true:

For more information, see the following:

If the forwarding rule's load balancing scheme is INTERNAL_SELF_MANAGED for Cloud Service Mesh, it must have a unique IP address.

Port specifications

The following table summarizes the valid port configurations, based on the load balancing scheme and the target of the forwarding rule.

Product Load balancing scheme Target Port requirements
Global external Application Load Balancer Regional external Application Load Balancer EXTERNAL_MANAGED Target HTTP proxyTarget HTTPS proxy Can reference exactly one port from 1-65535
Classic Application Load Balancer EXTERNAL Target HTTP proxyTarget HTTPS proxy Can reference exactly one port from 1-65535
Cross-region internal Application Load Balancer Regional internal Application Load Balancer INTERNAL_MANAGED Target HTTP proxyTarget HTTPS proxy Can reference exactly one port from 1-65535
Global external proxy Network Load Balancer EXTERNAL_MANAGED Target TCP proxyTarget SSL proxy Can reference exactly one port from 1-65535
Classic proxy Network Load Balancer EXTERNAL Target TCP proxyTarget SSL proxy Can reference exactly one port from 1-65535
Regional external proxy Network Load Balancer EXTERNAL_MANAGED Target TCP proxy Can reference exactly one port from 1-65535
Regional internal proxy Network Load Balancer INTERNAL_MANAGED Target TCP proxy Can reference exactly one port from 1-65535
Cross-region internal proxy Network Load Balancer INTERNAL_MANAGED Target TCP proxy Can reference exactly one port from 1-65535
External passthrough Network Load Balancer EXTERNAL Backend service If the forwarding rule protocol is TCP or UDP, you can configure: A list of up to five (contiguous or non-contiguous) ports, or, A single port range (contiguous), or, All ports. To configure all ports, either set --ports=ALL using the gcloud command line tool, or set allPorts to True using the API. If the forwarding rule protocol is L3_DEFAULT, you must configure all ports. To configure all ports, either set --ports=ALL using the gcloud command line tool, or set allPorts to True using the API.
Target pool Must be a single port range (contiguous) Specifying a port is optional for forwarding rules used with target pool-based external passthrough Network Load Balancers. If no port is specified, traffic from all ports (1-65535) is forwarded.
Internal passthrough Network Load Balancer INTERNAL Backend service Up to five (contiguous or non-contiguous) ports or you can configure all ports using one of these methods: set --ports=ALL using the gcloud command line tool, or set allPorts to True using the API.
Cloud Service Mesh INTERNAL_SELF_MANAGED Target HTTP proxyTarget HTTPS proxy Must be a single value. Within a VPC network, no two forwarding rules for Cloud Service Mesh can have the same IP address and port specification.
Classic VPN EXTERNAL Target VPN gateway Can reference exactly one of the following ports: 500, 4500

IAM conditions

With Identity and Access Management (IAM) conditions, you can set conditions to control which roles are granted to principals. This feature lets you grant permissions to principals if configured conditions are met.

An IAM condition checks the load balancing scheme (for example,INTERNAL or EXTERNAL) in the forwarding rule and allows (or disallows) creation of the forwarding rule. If a principal tries to create a forwarding rule without permission, an error message appears.

For more information, see IAM Conditions.

If you're using the Google Cloud console to set up a load balancer, the forwarding rule is set up implicitly as part of your frontend configuration. If you're using the Google Cloud CLI or the API, you need to configure the forwarding rule explicitly.

After creating a forwarding rule, you can make limited changes to it. For example, after a forwarding rule is defined, you can't change its IP address, port number, or protocol. However, you can update certain settings for forwarding rules by editing the frontend configuration of the load balancer they are associated with. Use either the gcloud CLI or the API to make any other changes.

Change the IP address of a forwarding rule

You cannot change the IP address of an existing forwarding rule. To update the IP address of a forwarding rule, you must delete and recreate the rule as follows:

  1. Delete the forwarding rule using thegcloud compute forwarding-rules delete command or the forwardingRules.delete method.
  2. Recreate the forwarding rule using thegcloud compute forwarding-rules create command or the forwardingRules.insert method.

APIs

For descriptions of the properties and methods available to you when working with forwarding rules through the REST API, see the following:

Google Cloud CLI

For the gcloud CLI reference documentation, see the following:

gcloud compute forwarding-rules

What's next