Set up a regional external proxy Network Load Balancer with zonal NEG backends Stay organized with collections Save and categorize content based on your preferences.
A regional external proxy Network Load Balancer is a proxy-based regional Layer 4 load balancer thatlets you run and scale your TCP service traffic in a single region behindan external regional IP address. These load balancers distributeexternal TCP traffic from the internet to backends in the same region.
This guide contains instructions to set up a regional external proxy Network Load Balancerwith a zonal network endpoint group (NEG) backend.
Before you begin, review the following documents:
In this example, we'll use the load balancer to distribute TCP traffic acrossbackend VMs in two zonal NEGs in Region A. For purposes of theexample, the service is a set ofApache serversconfigured to respond on port80.
In this example, you configure the deployment shown in the following diagram.
This is a regional load balancer. All load balancer components(backend instance group, backend service, target proxy, and forwarding rule)must be in the same region.
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 | Compute Network Admin (roles/compute.networkAdmin) |
| Add and remove firewall rules | Compute Security Admin (roles/compute.securityAdmin) |
| Create instances | Compute Instance Admin (roles/compute.instanceAdmin) |
For more information, see the following guides:
Optional: Use BYOIP addresses
With bring your own IP (BYOIP), you can import your own public addresses toGoogle Cloud to use the addresses with Google Cloud resources. Forexample, if you import your own IPv4 addresses, you can assign one to theforwarding rule when you configure your load balancer. When you follow theinstructions in this document toconfigure the load balancer, provide the BYOIP address as theIP address.
For more information about using BYOIP, seeBring your own IP addresses.
Configure the network and subnets
You need a VPC network with two subnets, one for the loadbalancer's backends and the other for the load balancer's proxies. This isa regional load balancer. Traffic within the VPCnetwork is routed to the load balancer if the traffic's source is in asubnet in the same region as the load balancer.
This example uses the following VPC network, region, andsubnets:
Network: acustom-mode VPCnetwork named
lb-networkSubnet for backends: a subnet named
backend-subnetinRegion A that uses10.1.2.0/24for its primary IP addressrangeSubnet for proxies: a subnet named
proxy-only-subnetinRegion A that uses10.129.0.0/23for its primary IP addressrange
Create the network and subnet for backends
Console
In the Google Cloud console, go to theVPC networks page.
ClickCreate VPC network.
ForName, enter
lb-network.In theSubnets section, do the following:
- Set theSubnet creation mode toCustom.
- In theNew subnet section, enter the following information:
- Name:
backend-subnet - Region:
REGION_A - IP address range:
10.1.2.0/24
- Name:
- ClickDone.
ClickCreate.
gcloud
To create the custom VPC network, use the
gcloud computenetworks createcommand:gcloud compute networks create lb-network --subnet-mode=custom
To create a subnet in the
lb-networknetwork in theREGION_Aregion,use thegcloud compute networks subnets createcommand:gcloud compute networks subnets create backend-subnet \ --network=lb-network \ --range=10.1.2.0/24 \ --region=REGION_A
Create the proxy-only subnet
Aproxy-only subnet provides aset of IP addresses that Google uses to run Envoy proxies on your behalf. Theproxies terminate connections from the client and create new connections to thebackends.
This proxy-only subnet is used by all Envoy-based load balancers inRegion A of thelb-network VPC network.
Console
If you're using the Google Cloud console, you can wait and create theproxy-only subnet later on theLoad balancing page.
If you want to create the proxy-only subnet now, use the following steps:
In the Google Cloud console, go to theVPC networks page.
Click the name of the Shared VPC network:
lb-network.ClickAdd subnet.
ForName, enter
proxy-only-subnet.ForRegion, select
REGION_A.SetPurpose toRegional Managed Proxy.
ForIP address range, enter
10.129.0.0/23.ClickAdd.
gcloud
To create the proxy-only subnet, use thegcloud compute networks subnetscreate command:
gcloud compute networks subnets create proxy-only-subnet \ --purpose=REGIONAL_MANAGED_PROXY \ --role=ACTIVE \ --region=REGION_A \ --network=lb-network \ --range=10.129.0.0/23
Create firewall rules
In this example, you create the following firewall rules:
fw-allow-health-check. An ingress rule, applicable to the Google Cloudinstances being load balanced, that allows traffic from the load balancer andGoogle Cloud health checking systems (130.211.0.0/22and35.191.0.0/16). This example uses the target tagallow-health-checktoidentify the backend VMs to which it should apply.fw-allow-ssh. An ingress rule that allows incoming SSH connectivity on TCPport22from any address. You can choose a more restrictive source IP rangefor this rule; for example, you can specify only the IP ranges of the systemsfrom which you initiate SSH sessions. This example uses the target tagallow-sshto identify the VMs to which it should apply.fw-allow-proxy-only-subnet. An ingressallowfirewall rule for theproxy-only subnet that allows the load balancer to communicate with backendinstances on TCP port80. This example uses the target tagallow-proxy-only-subnettoidentify the backend VMs to which it should apply.
Console
In the Google Cloud console, go to theFirewall policies page.
ClickCreate firewall rule, and then complete the following fields:
- Name:
fw-allow-health-check - Network:
lb-network - Targets:Specified target tags
- Target tags:
allow-health-check - Source filter:IPv4 ranges
- Source IPv4 ranges:
130.211.0.0/22and35.191.0.0/16 - Protocols and ports:
- ChooseSpecified protocols and ports.
- Select theTCP checkbox, and then enter
80for the portnumber.
- Name:
ClickCreate.
ClickCreate firewall rule a second time to create the ruleto allow incoming SSH connections:
- Name:
fw-allow-ssh - Network:
lb-network - Priority:
1000 - Direction of traffic:Ingress
- Action on match:Allow
- Targets:Specified target tags
- Target tags:
allow-ssh - Source filter:IPv4 ranges
- Source IPv4 ranges:
0.0.0.0/0 - Protocols and ports:
- ChooseSpecified protocols and ports.
- Select theTCP checkbox, and then enter
22for the portnumber.
- Name:
ClickCreate.
ClickCreate firewall rule a third time to create the rule toallow incoming connections from the proxy-only subnet to the Google Cloudbackends:
- Name:
fw-allow-proxy-only-subnet - Network:
lb-network - Priority:
1000 - Direction of traffic:Ingress
- Action on match:Allow
- Targets:Specified target tags
- Target tags:
allow-proxy-only-subnet - Source filter:IPv4 ranges
- Source IPv4 ranges:
10.129.0.0/23 - Protocols and ports:
- ChooseSpecified protocols and ports.
- Select theTCP checkbox, and then enter
80for the portnumber.
- Name:
ClickCreate.
gcloud
Create the
fw-allow-health-checkrule to allowthe Google Cloud health checks to reach thebackend instances on TCP port80:gcloud compute firewall-rules create fw-allow-health-check \ --network=lb-network \ --action=allow \ --direction=ingress \ --target-tags=allow-health-check \ --source-ranges=130.211.0.0/22,35.191.0.0/16 \ --rules=tcp:80
Create the
fw-allow-sshfirewall rule to allow SSH connectivity toVMs with the network tagallow-ssh. When you omitsource-ranges,Google Cloudinterprets the rule to mean anysource.gcloud compute firewall-rules create fw-allow-ssh \ --network=lb-network \ --action=allow \ --direction=ingress \ --target-tags=allow-ssh \ --rules=tcp:22
Create an ingress allow firewall rule for the proxy-only subnet to allowthe load balancer to communicate with backend instances on TCP port
80:gcloud compute firewall-rules create fw-allow-proxy-only-subnet \ --network=lb-network \ --action=allow \ --direction=ingress \ --target-tags=allow-proxy-only-subnet \ --source-ranges=10.129.0.0/23 \ --rules=tcp:80
Reserve the load balancer's IP address
Console
In the Google Cloud console, go to theReserve a static address page.
Choose a name for the new address.
ForNetwork Service Tier, selectStandard.
ForIP version, selectIPv4. IPv6 addresses are not supported.
ForType, selectRegional.
ForRegion, select
REGION_A.Leave theAttached to option set toNone. After you create theload balancer, this IP address is attached to the loadbalancer's forwarding rule.
ClickReserve to reserve the IP address.
gcloud
To reserve a static external IP address, use the
gcloud compute addresses createcommand:gcloud compute addresses createADDRESS_NAME \ --region=REGION_A \ --network-tier=STANDARD
Replace
ADDRESS_NAMEwith the name thatyou want to call this address.To view the result, use the
gcloud compute addresses describecommand:gcloud compute addresses describeADDRESS_NAME
Set up the zonal NEG
Set up a zonal NEG withGCE_VM_IP_PORT type endpointsin Region A. First create the VMs, and thencreate a zonal NEG and add the VMs' network endpoints to the NEG.
Create VMs
Console
In the Google Cloud console, go to theVM instances page.
ClickCreate instance.
SetName to
vm-a1.ForRegion, select
REGION_A.ForZone, select
ZONE_A.In theBoot disk section, ensure thatDebian GNU/Linux 12 (bookworm) is selected for the boot diskoptions. ClickChoose to change the image if necessary.
ClickAdvanced options.
ClickNetworking, and then configure the following fields:
- ForNetwork tags, enter
allow-ssh,allow-health-check,andallow-proxy-only-subnet. - ForNetwork interfaces, select the following:
- Network:
lb-network - Subnet:
backend-subnet
- Network:
- ForNetwork tags, enter
ClickManagement. Enter the following script into theStartup script field:
#! /bin/bashapt-get updateapt-get install apache2 -ya2ensite default-ssla2enmod sslvm_hostname="$(curl -H "Metadata-Flavor:Google" \http://metadata.google.internal/computeMetadata/v1/instance/name)"echo "Page served from: $vm_hostname" | \tee /var/www/html/index.htmlsystemctl restart apache2
ClickCreate.
Repeat the previous steps to create three more VMs. Use the followingname and zone combinations:
- Name:
vm-a2| Zone:ZONE_A - Name:
vm-b1| Zone:ZONE_B - Name:
vm-b2| Zone:ZONE_B
- Name:
gcloud
To create the VMs, use thegcloud compute instances create command two times. Use the following combinations forVM_NAME andZONE. The script contents are identical for both VMs:
VM_NAME:vm-a1andZONE:ZONE_AVM_NAME:vm-a2andZONE:ZONE_AVM_NAME:vm-b1andZONE:ZONE_BVM_NAME:vm-b2andZONE:ZONE_B
gcloud compute instances createVM_NAME \ --zone=ZONE \ --image-family=debian-12 \ --image-project=debian-cloud \ --tags=allow-ssh,allow-health-check,allow-proxy-only-subnet \ --subnet=backend-subnet \ --metadata=startup-script='#! /bin/bash apt-get update apt-get install apache2 -y a2ensite default-ssl a2enmod ssl vm_hostname="$(curl -H "Metadata-Flavor:Google" \ http://metadata.google.internal/computeMetadata/v1/instance/name)" echo "Page served from: $vm_hostname" | \ tee /var/www/html/index.html systemctl restart apache2'
Create the zonal NEGs
Console
Create a zonal network endpoint group
In the Google Cloud console, go to theNetwork endpoint groups page.
ClickCreate network endpoint group.
ForName, enter
zonal-neg-a.ForNetwork endpoint group type, selectNetwork endpoint group(Zonal).
ForNetwork, select
lb-network.ForSubnet, select
backend-subnet.ForZone, select
ZONE_A.ForDefault port, enter
80.ClickCreate.
Repeat all the steps in this section to create a second zonal NEG withthe following changes in settings:
- Name:
zonal-neg-b - Zone:
ZONE_B
- Name:
Add endpoints to the zonal NEGs
In the Google Cloud console, go to theNetwork endpoint groups page.
Click the name of the network endpoint group that you createdin the previous step (for example,
zonal-neg-a).On theNetwork endpoint group details page, in theNetwork endpoints in this group section, clickAdd networkendpoint.
Select a VM instance (for example,
vm-a1).In theNetwork interface section, the VM name, zone, andsubnet are displayed.
- ForIP address, enter the IP address of the new network endpoint.To get the IP address, clickCheck primary IP addresses and alias IPrange in nic0.
- ForPort type, selectDefault. The endpoint uses the default port
80for all endpoints in the network endpoint group. This is sufficientfor our example because the Apache server is serving requests at port80. - ClickCreate.
ClickAdd network endpoint. Select the second VM instance,
vm-a2, and repeat the previous steps to add its endpoints tozonal-neg-a.Repeat all the steps in this section to add endpoints from
vm-b1andvm-b2tozonal-neg-b.
gcloud
Create a zonal NEG in the
ZONE_Azone withGCE_VM_IP_PORTendpoints:gcloud compute network-endpoint-groups create zonal-neg-a \ --network-endpoint-type=GCE_VM_IP_PORT \ --zone=ZONE_A \ --network=lb-network \ --subnet=backend-subnet
You can either specify the
--default-portwhile creating the NEG,orspecify a port number for eachendpointas shown in the next step.Add endpoints to the zonal NEG:
gcloud compute network-endpoint-groups update zonal-neg-a \ --zone=ZONE_A \ --add-endpoint='instance=vm-a1,port=80' \ --add-endpoint='instance=vm-a2,port=80'
Create a zonal NEG in the
ZONE_Bzone withGCE_VM_IP_PORTendpoints:gcloud compute network-endpoint-groups create zonal-neg-b \ --network-endpoint-type=GCE_VM_IP_PORT \ --zone=ZONE_B \ --network=lb-network \ --subnet=backend-subnet
You can either specify the
--default-portwhile creating the NEG,orspecify a port number for eachendpointas shown in the next step.Add endpoints to the zonal NEG:
gcloud compute network-endpoint-groups update zonal-neg-b \ --zone=ZONE_B \ --add-endpoint='instance=vm-b1,port=80' \ --add-endpoint='instance=vm-b2,port=80'
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 regional workloads and clickNext.
- ClickConfigure.
Basic configuration
- ForName, enter
my-ext-tcp-lb. - ForRegion, select
REGION_A. - ForNetwork, select
lb-network.
Reserve a proxy-only subnet
Note: If you alreadycreated the proxy-only subnet,theReserve subnet button isn't displayed. You can skip thissection and continue with the steps in theConfigure the backendssection.- ClickReserve subnet.
- ForName, enter
proxy-only-subnet. - ForIP address range, enter
10.129.0.0/23. - ClickAdd.
Configure the backends
- ClickBackend configuration.
- In theBackend type list, selectZonal network endpoint group.
- In theProtocol list, selectTCP.
- Configure the health check:
- In theHealth check list, selectCreate a health check.
- In theName field, enter
tcp-health-check. - In theProtocol list, selectTCP.
- In thePort field, enter
80. - CLickCreate.
- Configure the first backend:
- ForNew backend, select zonal NEG
zonal-neg-a. - Retain the remaining default values, and then clickDone.
- ForNew backend, select zonal NEG
- Configure the second backend:
- ClickAdd backend.
- ForNew backend, select instance group
zonal-neg-b. - Retain the remaining default values, and then clickDone.
- Retain the remaining default values, and then clickSave.
- In the Google Cloud console, verify that there is a check mark next toBackend configuration. If not, double-check that you have completedall of the steps.
Configure the frontend
- ClickFrontend configuration.
- ForName, enter
ext-tcp-forwarding-rule. - ForNetwork Service Tier, selectStandard.
- ForIP address, select
ext-tcp-ip-address. - ForPort number, enter
9090. The forwarding rule onlyforwards packets with a matching destination port. - ForProxy protocol, selectOff because the PROXY protocoldoesn't work with the Apache HTTP Server software. For moreinformation, seePROXY protocol.
- ClickDone.
- In the Google Cloud console, verify that there is a check mark next toFrontend configuration. If not, double-check that you have completedall the previous steps.
Review and finalize
- ClickReview and finalize.
- Double-check your settings.
- ClickCreate.
gcloud
Create a regional health check for the backends:
gcloud compute health-checks create tcp tcp-health-check \ --region=REGION_A \ --use-serving-port
Create a backend service:
gcloud compute backend-services create external-tcp-proxy-bs \ --load-balancing-scheme=EXTERNAL_MANAGED \ --protocol=TCP \ --region=REGION_A \ --health-checks=tcp-health-check \ --health-checks-region=REGION_A
Add the zonal NEG in the
ZONE_Azone to the backend service:gcloud compute backend-services add-backend external-tcp-proxy-bs \ --network-endpoint-group=zonal-neg-a \ --network-endpoint-group-zone=ZONE_A \ --balancing-mode=CONNECTION \ --max-connections-per-endpoint=50 \ --region=REGION_A
Add the zonal NEG in the
ZONE_Bzone to the backend service:gcloud compute backend-services add-backend external-tcp-proxy-bs \ --network-endpoint-group=zonal-neg-b \ --network-endpoint-group-zone=ZONE_B \ --balancing-mode=CONNECTION \ --max-connections-per-endpoint=50 \ --region=REGION_A
Create the target TCP proxy:
gcloud compute target-tcp-proxies create ext-tcp-target-proxy \ --backend-service=external-tcp-proxy-bs \ --region=REGION_A
Create the forwarding rule. For
--ports, specify a single port numberfrom 1-65535. This example uses port9090. The forwarding rule onlyforwards packets with a matching destination port.gcloud compute forwarding-rules create ext-tcp-forwarding-rule \ --load-balancing-scheme=EXTERNAL_MANAGED \ --network=lb-network \ --network-tier=STANDARD \ --address=ext-tcp-ip-address \ --ports=9090 \ --region=REGION_A \ --target-tcp-proxy=ext-tcp-target-proxy \ --target-tcp-proxy-region=REGION_A
Test your load balancer
Note: It might take a few minutes for the load balancer configuration topropagate after you first deploy it.Now that you have configured your load balancer, you can test sendingtraffic to the load balancer's IP address.
Get the load balancer's IP address.
To get the IPv4 address, run the following command:
gcloud compute addresses describeADDRESS_NAME
Send traffic to your load balancer by running thefollowing command. Replace
LB_IP_ADDRESSwith your loadbalancer's IPv4 address.curl -m1LB_IP_ADDRESS:9090
What's next
- Convert proxy Network Load Balancer to IPv6
- External proxy Network Load Balancer overview.
- Proxy Network Load Balancer logging andmonitoring.
- Add a Private Service Connect.
- Clean up the load balancer 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 2026-02-19 UTC.