Set up a global external proxy Network Load Balancer (TCP proxy) with VM instance group backends Stay organized with collections Save and categorize content based on your preferences.
Google Cloud global external proxy Network Load Balancers let youuse a single IP address for all users around the world. Global external proxy Network Load Balancersautomatically route traffic to backend instances that are closest to the user.
This page contains instructions for setting up a global external proxy Network Load Balancerwith a target TCP proxy and VM instance group backends. Before you start, readtheExternal proxy Network Load Balancer overview for detailedinformation about how these load balancers work.
Setup overview
This example demonstrates how to set up an external proxy Network Load Balancer fora service that exists in two regions: Region A and Region B.For purposes of the example, the service is a set ofApacheservers configured to respond on port110. Many browsers don'tallow port110, so the testing section usescurl.
In this example, you configure the following:
- Four instances distributed between two regions
- Instance groups, which contain the instances
- A health check for verifying instance health
- A backend service, which monitors the instances and prevents themfrom exceeding configured usage
- The target TCP proxy
- An external static IPv4 address and forwarding rule that sends user trafficto the proxy
- An external static IPv6 address and forwarding rule that sends user trafficto the proxy
- A firewall rule that allows traffic from the load balancer andhealth checker to reach the instances
After the load balancer is configured, you test the configuration.
Permissions
To follow this guide, you must be able to create instances and modify anetwork in a project. You must be either a projectowner or editor, or you musthave all of the followingCompute Engine IAM roles:
| Task | Required Role |
|---|---|
| Create networks, subnets, and load balancer components | Network Admin |
| Add and remove firewall rules | Security Admin |
| Create instances | Compute Instance Admin |
For more information, see the following guides:
Configure the network and subnets
To create the example network and subnet, follow these steps.
Console
To support bothIPv4 and IPv6 traffic, use the following steps:
In the Google Cloud console, go to theVPC networks page.
ClickCreate VPC network.
Enter aName for the network.
Optional: If you want to configure internal IPv6 address ranges onsubnets in this network, complete these steps:
- ForVPC network ULA internal IPv6 range, selectEnabled.
ForAllocate internal IPv6 range, selectAutomatically orManually.
If you selectManually, enter a
/48range from within thefd20::/20range. If the range is in use, you are prompted to providea different range.
For theSubnet creation mode, chooseCustom.
In theNew subnet section, configure the following fields:
- In theName field, provide a name for the subnet.
- In theRegion field, select a region.
- ForIP stack type, selectIPv4 and IPv6 (dual-stack).
In theIP address range field, enter an IP address range. This is theprimary IPv4range for the subnet.
Although you can configure an IPv4 range of addresses forthe subnet, you cannot choose the range of the IPv6 addressesfor the subnet. Google provides a fixed size (
/64) IPv6 CIDRblock.ForIPv6 access type, selectExternal.
ClickDone.
To add a subnet in a different region, clickAdd subnet and repeatthe previous steps.
ClickCreate.
To support IPv4 traffic only, use the following steps:
In the Google Cloud console, go to theVPC networks page.
ClickCreate VPC network.
In theName field, enter a name for the network.
For theSubnet creation mode, chooseCustom.
In theNew subnet section, configure the following:
- In theName field, provide a name for the subnet.
- In theRegion field, select a region.
- ForIP stack type, selectIPv4 (single-stack).
- In theIP address range field, enter theprimary IPv4range for the subnet.
ClickDone.
To add a subnet in a different region, clickAdd subnet and repeatthe previous steps.
ClickCreate.
gcloud
Create the custom mode VPC network:
gcloud compute networks createNETWORK \ --subnet-mode=custom
Within the network, create a subnet for backends.
ForIPv4 and IPv6 traffic, use the following command to update asubnet:
gcloud compute networks subnets createSUBNET \ --stack-type=IPV4_IPV6 \ --ipv6-access-type=EXTERNAL \ --network=NETWORK \ --range=IPV4_RANGE \ --region=REGION_A
gcloud compute networks subnets createSUBNET_B \ --stack-type=IPV4_IPV6 \ --ipv6-access-type=EXTERNAL \ --network=NETWORK \ --range=IPV4_RANGE_B \ --region=REGION_B
ForIPv4 traffic only, use the following command:
gcloud compute networks subnets createSUBNET \ --network=NETWORK \ --stack-type=IPV4_ONLY \ --range=IPV4_RANGE \ --region=REGION_A
gcloud compute networks subnets createSUBNET_B \ --network=NETWORK \ --stack-type=IPV4_ONLY \ --range=IPV4_RANGE_B \ --region=REGION_B
Replace the following:
NETWORK: a name for the VPC networkIPV4_RANGE: the primary IPv4 range for the new subnet,in CIDR notation. For example,10.1.2.0/24.SUBNET: a name for the subnet
REGION_AorREGION_B: the name of theregion
Configure instance group backends
This section shows how to create basic instance groups, add instancesto them, and then add those instances to a backend service with a health check.A production system would normally usemanaged instance groups basedoninstance templates, but thisconfiguration is quicker for initial testing.
Configure instances
For testing purposes, install Apache on four instances, two in eachof two instance groups. Typically, external proxy Network Load Balancers aren't usedfor HTTP traffic, but Apache software is commonly usedfor testing.
In this example, the instances are created with the tagtcp-lb. This tag isused later by the firewall rule.
Console
Create instances
In the Google Cloud console, go to theVM instances page.
ClickCreate instance.
SetName to
vm-a1.Set theRegion to
REGION_A.Set theZone to
ZONE_A.ClickAdvanced options.
ClickNetworking and configure the following field:
- ForNetwork tags, enter
tcp-lb,allow-health-check-ipv6.
To support bothIPv4 and IPv6 traffic, use the following steps:
- In theNetwork interfaces section, clickEdit, and make thefollowing changes:
- Network:
NETWORK - Subnet:
SUBNET - IP stack type:IPv4 and IPv6 (dual-stack)
- Network:
- ClickDone
- ForNetwork tags, enter
ClickManagement. Enter the following script into theStartup script field.
sudo apt-get updatesudo apt-get install apache2 -ysudo sed -i '/Listen 80/c\Listen 110' /etc/apache2/ports.confsudo service apache2 restartecho '<!doctype html><html><body><h1>vm-a1</h1></body></html>' | sudo tee /var/www/html/index.html
ClickCreate.
Create
vm-a2with the same settings, except withthe following script in theStartup script field:sudo apt-get updatesudo apt-get install apache2 -ysudo sed -i '/Listen 80/c\Listen 110' /etc/apache2/ports.confsudo service apache2 restartecho '<!doctype html><html><body><h1>vm-a2</h1></body></html>' | sudo tee /var/www/html/index.html
Create
vm-b1with the same settings, except withRegion set toREGION_BandZone set toZONE_B.Enter the following script in theStartup script field:sudo apt-get updatesudo apt-get install apache2 -ysudo sed -i '/Listen 80/c\Listen 110' /etc/apache2/ports.confsudo service apache2 restartecho '<!doctype html><html><body><h1>vm-b1</h1></body></html>' | sudo tee /var/www/html/index.html
Create
vm-b2with the same settings, except withRegion set toREGION_BandZone set toZONE_B.Enter the following script in theStartup script field:sudo apt-get updatesudo apt-get install apache2 -ysudo sed -i '/Listen 80/c\Listen 110' /etc/apache2/ports.confsudo service apache2 restartecho '<!doctype html><html><body><h1>vm-b2</h1></body></html>' | sudo tee /var/www/html/index.html
gcloud
Create
vm-a1in zoneZONE_Agcloud compute instances create vm-a1 \ --image-family debian-12 \ --image-project debian-cloud \ --tags tcp-lb \ --zoneZONE_A \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo sed -i '/Listen 80/c\Listen 110' /etc/apache2/ports.conf sudo service apache2 restart echo '<!doctype html><html><body><h1>vm-a1</h1></body></html>' | tee /var/www/html/index.html EOF"
Create
vm-a2in zoneZONE_Agcloud compute instances create vm-a2 \ --image-family debian-12 \ --image-project debian-cloud \ --tags tcp-lb \ --zoneZONE_A \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo sed -i '/Listen 80/c\Listen 110' /etc/apache2/ports.conf sudo service apache2 restart echo '<!doctype html><html><body><h1>vm-a2</h1></body></html>' | tee /var/www/html/index.html EOF"
Create
vm-b1in zoneZONE_Bgcloud compute instances create vm-b1 \ --image-family debian-12 \ --image-project debian-cloud \ --tags tcp-lb \ --zoneZONE_B \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo sed -i '/Listen 80/c\Listen 110' /etc/apache2/ports.conf sudo service apache2 restart echo '<!doctype html><html><body><h1>vm-b1</h1></body></html>' | tee /var/www/html/index.html EOF"
Create
vm-b2in zoneZONE_Bgcloud compute instances create vm-b2 \ --image-family debian-12 \ --image-project debian-cloud \ --tags tcp-lb \ --zoneZONE_B \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo sed -i '/Listen 80/c\Listen 110' /etc/apache2/ports.conf sudo service apache2 restart echo '<!doctype html><html><body><h1>vm-b2</h1></body></html>' | tee /var/www/html/index.html EOF"
Create instance groups
In this section you create an instance group in each zone and add the instances.
Console
In the Google Cloud console, go to theInstance groups page.
ClickCreate instance group.
ClickNew unmanaged instance group.
Set theName to
instance-group-a.Set theZone to
ZONE_A.UnderPort mapping, clickAdd port.A load balancer sends traffic to an instance group through anamedport.Create a named port to map the incoming traffic to a specific portnumber.
- SetPort name to
tcp110. - SetPort numbers to
110.
- SetPort name to
UnderVM instances, select
vm-a1andvm-a2.Leave the other settings as they are.
ClickCreate.
Repeat the steps, but set the following values:
- Name:
instance-group-b - Region:
REGION_B - Zone:
ZONE_B - Port name:
tcp110 - Port numbers:
110 - Instances:vm-b1 andvm-b2.
- Name:
gcloud
Create the
instance-group-ainstance group.gcloud compute instance-groups unmanaged create instance-group-a \ --zoneZONE_A
Create a named port for the instance group.
gcloud compute instance-groups set-named-ports instance-group-a \ --named-ports tcp110:110 \ --zoneZONE_A
Add
vm-a1andvm-a2toinstance-group-a.gcloud compute instance-groups unmanaged add-instances instance-group-a \ --instances vm-a1,vm-a2 \ --zoneZONE_A
Create the
us-ig2instance group.gcloud compute instance-groups unmanaged create instance-group-b \ --zoneZONE_B
Create a named port for the instance group.
gcloud compute instance-groups set-named-ports instance-group-b \ --named-ports tcp110:110 \ --zoneZONE_B
Add
vm-b1andvm-b2to instance-group-bgcloud compute instance-groups unmanaged add-instances instance-group-b \ --instances vm-b1,vm-b2 \ --zoneZONE_B
You now have one instance group per region. Each instance group has two VM instances.
Create a firewall rule for the external proxy Network Load Balancer
Configure the firewall to allow traffic from the load balancer and healthchecker to the instances. In this case, we will open TCP port 110. The healthcheck will use the same port. Since the traffic between the load balancerand your instances uses IPv4, only IPv4 ranges need be opened.
Console
In the Google Cloud console, go to theFirewall policies page.
ClickCreate firewall rule.
In theName field, enter
allow-tcp-lb-and-health.Select a network.
UnderTargets, selectSpecified target tags.
SetTarget tags to
tcp-lb.SetSource filter toIPv4 ranges.
SetSource IPv4 ranges to
130.211.0.0/22,35.191.0.0/16.UnderProtocols and ports, setSpecified protocols and ports to
tcp:110.ClickCreate.
gcloud
gcloud compute firewall-rules create allow-tcp-lb-and-health \ --source-ranges 130.211.0.0/22,35.191.0.0/16 \ --target-tags tcp-lb \ --allow tcp:110
Create an IPv6 health check firewall rule
Ensure that you have an ingress rule that is applicable to the instancesbeing load balanced and that allows traffic from the Google Cloudhealth checking systems (2600:2d00:1:b029::/64). This example uses thetarget tagallow-health-check-ipv6 to identify the VM instances to whichit applies.
Without this firewall rule, thedefault denyingress rule blocks incoming IPv6traffic to the backend instances.
Note: You must create a firewall rule to allow health checks from the IP rangesof Google Cloud probe systems. For more information, seeprobe IPranges for moreinformation.Console
In the Google Cloud console, go to theFirewall policies page.
To allow IPv6 subnet traffic, clickCreate firewall rule again andenter the following information:
- Name:
fw-allow-lb-access-ipv6 - Select the network.
- Priority:
1000 - Direction of traffic:ingress
- Targets:Specified target tags
- Target tags:
allow-health-check-ipv6 - Source filter:IPv6 ranges
- Source IPv6 ranges:
2600:2d00:1:b029::/64,2600:2d00:1:1::/64 - Protocols and ports:Allow all
- Name:
ClickCreate.
gcloud
Create thefw-allow-lb-access-ipv6 firewall rule to allow communicationwith the subnet:
gcloud compute firewall-rules create fw-allow-lb-access-ipv6 \ --network=NETWORK \ --action=allow \ --direction=ingress \ --target-tags=allow-health-check-ipv6 \ --source-ranges=2600:2d00:1:b029::/64,2600:2d00:1:1::/64 \ --rules=all
Configure the load balancer
Console
Start your configuration
In the Google Cloud console, go to theLoad balancing page.
- ClickCreate load balancer.
- ForType of load balancer, selectNetwork Load Balancer (TCP/UDP/SSL) and clickNext.
- ForProxy or passthrough, selectProxy load balancer and clickNext.
- ForPublic facing or internal, selectPublic facing (external) and clickNext.
- ForGlobal or single region deployment, selectBest for global workloads and clickNext.
- ForLoad balancer generation, selectGlobal external proxy Network Load Balancer and clickNext.
- ClickConfigure.
Basic configuration
Set theName tomy-tcp-lb.
Backend configuration
- ClickBackend configuration.
- In theBackend type list, selectInstance groups.
- In theProtocol list, selectTCP.
- In theIP address selection policy list, selectPrefer IPv6.Tip: When you select theIP address selection policy, ensure that your backends support the selected traffic type.
- Configure the health check:
- In theHealth check list, selectCreate health check.
- In theName field, enter
my-tcp-health-check. - In theProtocol list, selectTCP.
- In thePort field, enter
110. - Retain the remaining default values.
- ClickCreate.
- Configure the first backend:
- UnderNew backend, select instance group
instance-group-a. - Retain the remaining default values.
- UnderNew backend, select instance group
- Configure the second backend:
- ForIP stack type, select
IPv4 and IPv6 (dual-stack). - ClickAdd backend.
- Select instance group
instance-group-b. - UnderPort numbers, delete
80and add110.
To support bothIPv4 and IPv6 traffic:
- ForIP stack type, select
- In the Google Cloud console, verify that there is a check mark next toBackend configuration. If not, double-check that you have completed all of the steps.
Frontend configuration
- ClickFrontend configuration.
- Add the first forwarding rule:
- Enter aName of
my-tcp-lb-forwarding-rule. - UnderProtocol, selectTCP.
- UnderIP address, selectCreate IP address:
- Enter aName of
tcp-lb-static-ip. - ClickReserve.
- Enter aName of
- SetPort to
110. - In this example, don't enable theProxy Protocol because it doesn't work with the Apache HTTP Server software. For more information, seeProxy protocol.
- ClickDone.
- Enter aName of
In the Google Cloud console, verify that there is a check mark next toFrontend configuration. If not, double-check that you have completed all the previous steps.
Review and finalize
- ClickReview and finalize.
- Review your load balancer configuration settings.
- Optional: ClickEquivalent code to view the REST API request that will be used to create the load balancer.
- ClickCreate.
gcloud
- Create a health check.
gcloud compute health-checks create tcp my-tcp-health-check --port 110
- Create a backend service.
gcloud beta compute backend-services create my-tcp-lb \ --load-balancing-scheme EXTERNAL_MANAGED \ --global-health-checks \ --global \ --protocol TCP \ --ip-address-selection-policy=PREFER_IPV6 \ --health-checks my-tcp-health-check \ --timeout 5m \ --port-name tcp110
Alternatively, you can configure encrypted communication from the load balancer to the instances with
--protocol SSL. Add instance groups to your backend service.
Note: A backend service with multiple endpoints must have unique IPv6 addresses. The endpoints can be in different subnets, but the same IPv6 address cannot be used for multiple endpoints.gcloud beta compute backend-services add-backend my-tcp-lb \ --global \ --instance-group instance-group-a \ --instance-group-zoneZONE_A \ --balancing-mode UTILIZATION \ --max-utilization 0.8
gcloud beta compute backend-services add-backend my-tcp-lb \ --global \ --instance-group instance-group-b \ --instance-group-zoneZONE_B \ --balancing-mode UTILIZATION \ --max-utilization 0.8
- Configure a target TCP proxy. If you want to turn on theproxy header, set it to
PROXY_V1instead ofNONE.gcloud beta compute target-tcp-proxies create my-tcp-lb-target-proxy \ --backend-service my-tcp-lb \ --proxy-header NONE
- Reserve global static IPv4 and IPv6 addresses.
Your customers can use these IP addresses to reach your load balanced service.
gcloud compute addresses create tcp-lb-static-ipv4 \ --ip-version=IPV4 \ --global
gcloud compute addresses create tcp-lb-static-ipv6 \ --ip-version=IPV6 \ --global
- Configure global forwarding rules for the two addresses.
gcloud beta compute forwarding-rules create my-tcp-lb-ipv4-forwarding-rule \ --load-balancing-scheme EXTERNAL_MANAGED \ --global \ --target-tcp-proxy my-tcp-lb-target-proxy \ --address tcp-lb-static-ipv4 \ --ports 110
Test the load balancer
Get the load balancer's IP address.
To get the IPv4 address, run the following command:
gcloud compute addresses describe tcp-lb-static-ipv4
To get the IPv6 address, run the following command:
gcloud compute addresses describe tcp-lb-static-ipv6
Send traffic to your load balancer by running thefollowing command. Replace
LB_IP_ADDRESSwith your load balancer's IPv4 or IPv6 address.curl -m1LB_IP_ADDRESS:110
For example, if the assigned IPv6 address is
[2001:db8:1:1:1:1:1:1/96]:110,the command should look like:curl -m1 http://[2001:db8:1:1:1:1:1:1]:110
If you can't reach the load balancer, try the steps describedunderTroubleshooting your setup.
Additional configuration options
This section expands on the configuration example to provide alternative andadditional configuration options. All of the tasks are optional. You canperform them in any order.
PROXY protocol for retaining client connection information
The proxy Network Load Balancer ends TCP connections fromthe client and creates new connections to the instances. By default, theoriginal client IP and port information is not preserved.
To preserve and send the original connection information to your instances,enablePROXY protocol version 1.This protocol sends an additional header that contains the sourceIP address, destination IP address, and port numbers to the instance as a partof the request.
Make sure that the proxy Network Load Balancer's backend instances are running servers that support PROXY protocol headers. If the servers are notconfigured to support PROXY protocol headers, the backend instances return emptyresponses.
If you set the PROXY protocol for user traffic, you can also set it for yourhealth checks. If you are checking health and servingcontent on the same port, set the health check's--proxy-header to match yourload balancer setting.
The PROXY protocol header is typically a single line of user-readabletext in the following format:
PROXY TCP4 <client IP> <load balancing IP> <source port> <dest port>\r\n
The following example shows a PROXY protocol:
PROXY TCP4 192.0.2.1 198.51.100.1 15221 110\r\n
In the preceding example, the client IP is192.0.2.1, the load balancing IP is198.51.100.1, the client port is15221, and the destination port is110.
When the client IP is not known, the load balancer generatesa PROXY protocol header in the following format:
PROXY UNKNOWN\r\n
Update PROXY protocol header for target proxy
Theexample load balancer setup on this page shows you how toenable the PROXY protocol header while creating the proxy Network Load Balancer. Use thesesteps to change the PROXY protocol header for an existing target proxy.
Console
In the Google Cloud console, go to theLoad balancing page.
- ClickEdit for your load balancer.
- ClickFrontend configuration.
- Change the value of theProxy protocol field toOn.
- ClickUpdate to save your changes.
gcloud
In the following command, edit the--proxy-header field and set it to eitherNONE orPROXY_V1 depending on your requirement.
gcloud compute target-tcp-proxies updateTARGET_PROXY_NAME \ --proxy-header=[NONE | PROXY_V1]
Configure session affinity
The example configuration creates a backend service without session affinity.
These procedures show you how to update a backend service for the exampleload balancer so that the backend service uses client IP affinity orgenerated cookie affinity.
When client IP affinity is enabled, the load balancer directs a particularclient's requests to the same backend VM based on a hash created from theclient's IP address and the load balancer's IP address (the external IP addressof an external forwarding rule).
Console
To enable client IP session affinity:
In the Google Cloud console, go to theLoad balancing page.
ClickBackends.
Clickmy-tcp-lb (the name of the backend serviceyou created for this example) and clickEdit.
On theBackend service details page, clickAdvancedconfiguration.
UnderSession affinity, selectClient IP from the menu.
ClickUpdate.
gcloud
Use the following Google Cloud CLI command to update themy-tcp-lb backendservice, specifying client IP session affinity:
gcloud compute backend-services update my-tcp-lb \ --global \ --session-affinity=CLIENT_IP
API
To set client IP session affinity, make aPATCH request to thebackendServices/patch method.
PATCHhttps://www.googleapis.com/compute/v1/projects/[PROJECT_ID]/global/us-west1/backendServices/my-tcp-lb{"sessionAffinity":"CLIENT_IP"}Enable connection draining
You can enable connection draining on backend services to ensure minimalinterruption to your users when an instance that is serving traffic isterminated, removed manually, or removed by an autoscaler. To learn more aboutconnection draining, read theEnabling connection drainingdocumentation.
What's next
- Convert proxy Network Load Balancer to IPv6
- External proxy Network Load Balancer overview
- Proxy Network Load Balancer logging and monitoring
- Convert to dual-stack backends
- Clean up a load balancing setup
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.