Reserve a static external IP address
You can reserve static external IP addresses. You can also list and releaseyour reserved static external IP addresses. To assign a static external IPaddress to a virtual machine (VM) instance, seeConfigure static external IP addresses.
External IP addresses can bestatic or ephemeral.If a VM requires a fixed external IP address that does not change, youcan obtain a static external IP address. You can reserve new external IPaddresses or promote existing ephemeral external IP addresses.
If you require a static internal IP address, seeReserve a static internal IP addressinstead.
Before you begin
- Read aboutIP addresses.
- Read aboutquotas and limits for static external IP addresses.
- Read aboutexternal IP address pricing.
- If you haven't already, set up authentication.Authentication is the process by which your identity is verified for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate as follows.
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.Terraform
To use the Terraform samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up ADC for a local development environment in the Google Cloud authentication documentation.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.
Required roles
To get the permissions that you need to reserve and manage static IP addresses, ask your administrator to grant you theCompute Network Admin (roles/compute.networkAdmin) IAM role on your project. For more information about granting roles, seeManage access to projects, folders, and organizations.
This predefined role contains the permissions required to reserve and manage static IP addresses. To see the exact permissions that are required, expand theRequired permissions section:
Required permissions
The following permissions are required to reserve and manage static IP addresses:
on the IP addresscompute.addresses.createon the IP addresscompute.addresses.createInternalon the networkcompute.networks.liston the subnetcompute.subnetworks.useon the subnetcompute.subnetworks.list
You might also be able to get these permissions withcustom roles or otherpredefined roles.
About static external IP addresses
A static external IP address is the IP address that is reserved for your resourceuntil you decide torelease it. If you have an IP address thatyour customers or users rely on to access your service, you can reserve that IPaddress so that only your resource can use it. You can alsopromote an ephemeral external IP addressto a static external IP address.
For more information, seeIP addresses.
Note: Static external IP addresses are not announced to the public internetuntil you associate them with a resource, such as a VM or an externalforwarding rule.The following table lists the static external IP addresses supported byGoogle Cloud.
| IP address type | Resource | IP range | Source | Associated with |
|---|---|---|---|---|
| Regional external IPv4 addresses | VMs and regional load balancers | /32 | Google's pool of external IP addresses | Project |
| Regional external IPv6 addresses | VMs and supported regional load balancers | /96 | Subnet's external IPv6 address range | Subnet |
| Global external IPv4 addresses | Global load balancers | /32 | Google's pool of external IP addresses | Project |
| Global external IPv6 addresses | Global load balancers | /64 | Google's pool of external IP addresses | Project |
For a list of regional and global load balancers, see theSummary of load balancer types.
Assigned external IP addresses exist on the same physical host as the VMand exist in the same region as the VM for all purposes, includingrouting, latency, and pricing. This is true regardless ofinternet geolocationlookup information.
Limitations
Only one resource at a time can use a static external IP address.
There is no way to check whether an IP address is static or ephemeral afterit has been assigned to a resource. You can compare the IP address againstthe list of static external IP addresses reserved to that project. Use the
gcloud compute addresses listsub-commandto see a list of static external IP addresses available to theproject.Each VM can have multiple network interfaces,and each interface can have the following IP addresses assignedaccording to itsstack type:
- IPv4-only interfaces:
- An internal IPv4 address (required)
- An external IPv4 address (optional)
- Dual-stack (IPv4 and IPv6) interfaces:
- An internal IPv4 address (required)
- An external IPv4 address (optional)
- A
/96IPv6 address range, either internal or external, but not both (required)
- IPv6-only interfaces:
- A
/96IPv6 address range, either internal or external, but not both (required)
- A
- IPv4-only interfaces:
You can't unassign or change the external IPv6 address of a VM with anIPv6-only network interface. You can, however, promote an ephemeral externalIP address of a resource to a static external IP address so that the addressremains reserved even after the resource is deleted.
You cannot change the name of a static IP address.
Note: Network interfaces can receive traffic from multiple forwarding rules, which might serve other external IP addresses. Any number of external IP addresses can reference a network interface through these forwarding rules, but each network interface can be assigned only one external IPv4 address and one external/96 IPv6 address range.
For more information about load balancing and forwarding rules, read theload balancing documentation.
Reserve a new static external IP address
After reserving the address, assign it to anew VMwhile creating it or to anexisting VM.
Note: If you reserve a static external IP address but don't assign it toa resource such as a VM or a forwarding rule, then you are charged at ahigher rate than for static and ephemeral external IP addresses that arein use. For more information, seeExternal IP address pricing.Console
- In the Google Cloud console, go to theIP addresses page.
- ClickReserve external static IP address.
- In theName field, enter an IP address name.
- Specify whether the network service tier isPremium orStandard.IPv6 static address reservation is supported only in the Premium tier.
- Specify whether it is anIPv4 orIPv6 address.
- Specify whether this IP address isRegional orGlobal.
- If you are reserving a static IP address for a global load balancer,chooseGlobal and then clickReserve.
- If you are reserving a static IP address for a VM or for aregional load balancer, chooseRegional, and then select theregion to create the address in.
If you are reserving a regional external IPv6 address, then also choosethe following:
- Network: the VPC network
- Subnetwork: the subnet from which to assign the static regional IPv6 address
Static IPv6 range: to specify a static external IPv6 address range toreserve, selectLet me choose, and then enter a custom
/96IPv6address range from the subnet's/64external IPv6 address range. Otherwise,the system automatically assigns a static external IPv6 address range in thesubnet for you.For Google-provided external IPv6 subnet ranges, IP addresses for VMsmust be from the first half (
/65) of the subnet's/64external IPv6address range and IP addresses for load balancingmust be from the second half (/65). For more information, seeExternal IPv6 specifications.Endpoint type: chooseVM instance orExternal passthrough Network Load Balancer
Optional: If you are reserving the static external IP address for a VM,then in theAttached to list, select a VM toattach the IP address to.
ClickReserve to reserve the IP address.
gcloud
To reserve a static external IP address, use thegcloud compute addresses create command.
Use the following instructions to reserve a static external IPv4 or IPv6 address:
Note: Global IP addresses can be used only with global load balancers.To reserve a global external IP address:
gcloud compute addresses createADDRESS_NAME \ --global \ --ip-version=IP_VERSION
Replace the following:
ADDRESS_NAME: the name that you want to associate with this address.IP_VERSION: the IP version, eitherIPv4orIPv6.
To reserve a regional external IPv4 address:
gcloud compute addresses createADDRESS_NAME \ --region=REGION
Replace the following:
ADDRESS_NAME: the name that you want to associate with this address.REGION: a region for the IP address.
To reserve a regional external IPv6 address:
gcloud compute addresses createADDRESS_NAME \ --region=REGION \ --subnet=SUBNET_NAME \ --ip-version=IPV6 \ --endpoint-type=ENDPOINT_TYPE \ --addresses=IPV6_ADDRESS
Replace the following:
ADDRESS_NAME: the name that you want to associate with this address.REGION: a region for the IP address.SUBNET_NAME: the subnet to assign the staticregional IPv6 address from. Thesubnet must have anassigned external IPv6 addressrange.ENDPOINT_TYPE: for regional external IPv6 addresses,specify the endpoint type, eitherVMorNETLB.IPV6_ADDRESS: the IPv6 address to reserve,which must be a/96IPv6 address range from the subnet. Ifunspecified, an IPv6 address is automatically allocated.For Google-provided external IPv6 subnet ranges, IP addresses for VMsmust be from the first half (
/65) of the subnet's/64external IPv6address range and IP addresses for load balancingmust be from the second half (/65). For more information, seeExternal IPv6 specifications.
To view the result, use thegcloud compute addresses describe command:
gcloud compute addresses describeADDRESS_NAME
Terraform
You can use thegoogle_compute_address resourceto create a regional external IP address.
resource "google_compute_address" "default" { name = "my-test-static-ip-address" region = "us-central1"}The following sample shows how to use thegoogle_compute_global_address resourceto create a global external IPv6 address:
resource "google_compute_global_address" "default" { project = var.project_id # Replace this with your service project ID in quotes name = "ipv6-address" address_type = "EXTERNAL" ip_version = "IPV6"}API
To create a regional IPv4 address, call the regional
addresses.insertmethod:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/addresses
Your request body should contain the following:
{ "name": "ADDRESS_NAME"}Replace the following:
PROJECT_ID: the project ID for this requestREGION: the name of the region for this requestADDRESS_NAME: the name that you want to associate with the address
For global static IPv4 addresses, call the
globalAddresses.insertmethod:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/addresses
Your request body should contain the following:
{ "name": "ADDRESS_NAME"}For global static IPv6 addresses, call the
globalAddresses.insertmethod:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/addresses
Your request body should contain the following:
{ "name": "ADDRESS_NAME", "ipVersion": "IPV6"}To see the result, use the
addresses.getmethod.For regional static IPv6 addresses, call the
addresses.insertmethod:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/addresses
Your request body should contain the following:
{ "name": "ADDRESS_NAME", "ipVersion": "IPV6", "ipv6EndpointType": "VM|LB", "networkTier": "PREMIUM", "subnetwork": "SUBNET" "address": "IPV6_ADDRESS"}Replace the following:
SUBNET: the subnet for this project.IPV6_ADDRESS: the IPv6 address to reserve, whichmust be a/96IPv6 address range from the subnet. If unspecified, anIP address is automatically allocated.For Google-provided external IPv6 subnet ranges, IP addresses for VMsmust be from the first half (
/65) of the subnet's/64external IPv6address range and IP addresses for load balancingmust be from the second half (/65). For more information, seeExternal IPv6 specifications.
To see the result, use the
addresses.getmethod.
Go
import("context""fmt""io"compute"cloud.google.com/go/compute/apiv1""cloud.google.com/go/compute/apiv1/computepb")// reserveNewRegionalExternal reserves a new regional external IP address in Google Cloud Platform.funcreserveNewRegionalExternal(wio.Writer,projectID,region,addressNamestring,isPremiumbool)(*computepb.Address,error){// projectID := "your_project_id"// region := "europe-central2"// addressName := "your_address_name"// isPremium := truectx:=context.Background()networkTier:=computepb.AccessConfig_STANDARD.String()ifisPremium{networkTier=computepb.AccessConfig_PREMIUM.String()}address:=&computepb.Address{Name:&addressName,NetworkTier:&networkTier,}client,err:=compute.NewAddressesRESTClient(ctx)iferr!=nil{returnnil,fmt.Errorf("NewAddressesRESTClient: %w",err)}deferclient.Close()req:=&computepb.InsertAddressRequest{Project:projectID,Region:region,AddressResource:address,}op,err:=client.Insert(ctx,req)iferr!=nil{returnnil,fmt.Errorf("unable to reserve regional address: %w",err)}err=op.Wait(ctx)iferr!=nil{returnnil,fmt.Errorf("waiting for the regional address reservation operation to complete: %w",err)}addressResult,err:=client.Get(ctx,&computepb.GetAddressRequest{Project:projectID,Region:region,Address:addressName,})iferr!=nil{returnnil,fmt.Errorf("unable to get reserved regional address: %w",err)}fmt.Fprintf(w,"Regional address %v reserved: %v",addressName,addressResult.GetAddress())returnaddressResult,err}// reserveNewGlobalExternal reserves a new global external IP address in Google Cloud Platform.funcreserveNewGlobalExternal(wio.Writer,projectID,addressNamestring,isV6bool)(*computepb.Address,error){// projectID := "your_project_id"// addressName := "your_address_name"// isV6 := falsectx:=context.Background()ipVersion:=computepb.Address_IPV4.String()ifisV6{ipVersion=computepb.Address_IPV6.String()}address:=&computepb.Address{Name:&addressName,IpVersion:&ipVersion,}client,err:=compute.NewGlobalAddressesRESTClient(ctx)iferr!=nil{returnnil,fmt.Errorf("NewGlobalAddressesRESTClient: %w",err)}deferclient.Close()req:=&computepb.InsertGlobalAddressRequest{Project:projectID,AddressResource:address,}op,err:=client.Insert(ctx,req)iferr!=nil{returnnil,fmt.Errorf("unable to reserve global address: %w",err)}err=op.Wait(ctx)iferr!=nil{returnnil,fmt.Errorf("waiting for the global address reservation operation to complete: %w",err)}addressResult,err:=client.Get(ctx,&computepb.GetGlobalAddressRequest{Project:projectID,Address:addressName,})iferr!=nil{returnnil,fmt.Errorf("unable to get reserved global address: %w",err)}fmt.Fprintf(w,"Global address %v reserved: %v",addressName,addressResult.GetAddress())returnaddressResult,nil}Java
importcom.google.cloud.compute.v1.Address;importcom.google.cloud.compute.v1.Address.AddressType;importcom.google.cloud.compute.v1.Address.IpVersion;importcom.google.cloud.compute.v1.Address.NetworkTier;importcom.google.cloud.compute.v1.AddressesClient;importcom.google.cloud.compute.v1.GlobalAddressesClient;importcom.google.cloud.compute.v1.InsertAddressRequest;importcom.google.cloud.compute.v1.InsertGlobalAddressRequest;importcom.google.common.collect.Lists;importjava.io.IOException;importjava.util.List;importjava.util.UUID;importjava.util.concurrent.ExecutionException;importjava.util.concurrent.TimeUnit;importjava.util.concurrent.TimeoutException;publicclassReserveNewExternalAddress{publicstaticvoidmain(String[]args)throwsIOException,ExecutionException,InterruptedException,TimeoutException{// TODO(developer): Replace these variables before running the sample.// Project ID or project number of the Google Cloud project you want to use.StringprojectId="your-project-id";// Address name you want to use.StringaddressName="your-address-name";// 'IPV4' or 'IPV6' depending on the IP version. IPV6 if True.booleanipV6=false;// 'STANDARD' or 'PREMIUM' network tier. Standard option available only in regional ip.booleanisPremium=false;// region (Optional[str]): The region to reserve the IP address in, if regional.// Must be None if global.Stringregion=null;reserveNewExternalIpAddress(projectId,addressName,ipV6,isPremium,region);}// Reserves a new external IP address in the specified project and region.publicstaticList<Address>reserveNewExternalIpAddress(StringprojectId,StringaddressName,booleanipV6,booleanisPremium,Stringregion)throwsIOException,ExecutionException,InterruptedException,TimeoutException{StringipVersion=ipV6?IpVersion.IPV6.name():IpVersion.IPV4.name();StringnetworkTier=!isPremium &®ion!=null?NetworkTier.STANDARD.name():NetworkTier.PREMIUM.name();Address.Builderaddress=Address.newBuilder().setName(addressName).setAddressType(AddressType.EXTERNAL.name()).setNetworkTier(networkTier);// Use global client if no region is specifiedif(region==null){// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.try(GlobalAddressesClientclient=GlobalAddressesClient.create()){address.setIpVersion(ipVersion);InsertGlobalAddressRequestaddressRequest=InsertGlobalAddressRequest.newBuilder().setProject(projectId).setRequestId(UUID.randomUUID().toString()).setAddressResource(address.build()).build();client.insertCallable().futureCall(addressRequest).get(30,TimeUnit.SECONDS);returnLists.newArrayList(client.list(projectId).iterateAll());}}else{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.try(AddressesClientclient=AddressesClient.create()){address.setRegion(region);InsertAddressRequestaddressRequest=InsertAddressRequest.newBuilder().setProject(projectId).setRequestId(UUID.randomUUID().toString()).setAddressResource(address.build()).setRegion(region).build();client.insertCallable().futureCall(addressRequest).get(30,TimeUnit.SECONDS);returnLists.newArrayList(client.list(projectId,region).iterateAll());}}}}Python
fromtypingimportOptionalfromgoogle.cloud.compute_v1.services.addresses.clientimportAddressesClientfromgoogle.cloud.compute_v1.services.global_addressesimportGlobalAddressesClientfromgoogle.cloud.compute_v1.typesimportAddressdefreserve_new_external_ip_address(project_id:str,address_name:str,is_v6:bool=False,is_premium:bool=False,region:Optional[str]=None,):""" Reserves a new external IP address in the specified project and region. Args: project_id (str): Your Google Cloud project ID. address_name (str): The name for the new IP address. is_v6 (bool): 'IPV4' or 'IPV6' depending on the IP version. IPV6 if True. is_premium (bool): 'STANDARD' or 'PREMIUM' network tier. Standard option available only in regional ip. region (Optional[str]): The region to reserve the IP address in, if regional. Must be None if global. Returns: None """ip_version="IPV6"ifis_v6else"IPV4"network_tier="STANDARD"ifnotis_premiumandregionelse"PREMIUM"address=Address(name=address_name,address_type="EXTERNAL",network_tier=network_tier,)ifnotregion:# global IP addressclient=GlobalAddressesClient()address.ip_version=ip_versionoperation=client.insert(project=project_id,address_resource=address)else:# regional IP addressaddress.region=regionclient=AddressesClient()operation=client.insert(project=project_id,region=region,address_resource=address)operation.result()print(f"External IP address '{address_name}' reserved successfully.")Promote an ephemeral external IP address
If your VM has anephemeral external IP addressand you want to permanently assign the IP address to your project, promote theephemeral external IP address to a static external IP address. Promoting anephemeral external IP address to reserved does not cause Google Cloud todrop packets sent to the VM. This includes packets sent to the VMdirectly or by means of a load balancer.
Console
- Go to theIP addresses page.
- ClickExternal IP addresses.
- Optional: In theFilter field, search for the ephemeral IP addressthat you want to promote.
- In theMore actions menu () of the IP addressthat you want to promote, selectPromote to static IP address.
- Enter a name for the new static IP address, and then clickReserve.
gcloud
Use the following instructions to promote a static external IPv4 or IPv6address:
To promote an ephemeral external IPv4 address to a static external IPv4address, provide the ephemeral external IP address by using the
--addressesflag with thecompute addresses createcommand.Use theregionflag to promote an ephemeral regional IP address ortheglobalflag to promote an ephemeral global IP address.gcloud compute addresses createADDRESS_NAME --addresses=IP_ADDRESS \ [--region=REGION | --global]
Replace the following:
ADDRESS_NAME: the name that you want toassociate with this address.IP_ADDRESS: the IP address that you wantto promote.REGION: the region that the regional IPaddress belongs to.
To promote an ephemeral regional external IPv6 address to a staticregional external IPv6 address, provide the ephemeral external IPaddress by using the
--addressesflag with thegcloud compute addresses createcommand.gcloud compute addresses createADDRESS_NAME \ --region=REGION \ --addresses=IPV6_ADDRESS \ --prefix-length=96
Replace the following:
ADDRESS_NAME: a name for the IP addressresource.REGION: the region for the IPv6 addressresource.IPV6_ADDRESS: the IPv6 address that you'repromoting.
API
To promote an ephemeral regional IP address, call theaddresses.insert method:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/addresses
To promote an ephemeral global IP address, make aPOST request to thefollowing URI:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/addresses
Specify the values for the required fields of the request body:
For IPv4 addresses, your request body should contain the followingfields:
{ "name": "ADDRESS_NAME", "address": "IPV4_ADDRESS" "addressType": "EXTERNAL"}For IPv6 addresses, your request body should contain the followingfields:
{ "name": "ADDRESS_NAME", "address": "IPV6_ADDRESS" "prefixLength": 96 "addressType": "EXTERNAL"}Replace the following:
ADDRESS_NAME: the name that you want toassociate with this addressIPV4_ADDRESS|IPV6_ADDRESS: the IPv4 or IPv6address that you want to promoteREGION: the region that the IPv4 or IPv6address belongs toPROJECT_ID: the project ID for this request
Go
import("context""fmt""io"compute"cloud.google.com/go/compute/apiv1"computepb"cloud.google.com/go/compute/apiv1/computepb""google.golang.org/protobuf/proto")// promoteEphemeralAddress promotes an ephemeral IP address to a reserved static external IP address.funcpromoteEphemeralAddress(wio.Writer,projectID,region,ephemeralIP,addressNamestring)error{// projectID := "your_project_id"// region := "europe-central2"// ephemeral_ip := "214.123.100.121"ctx:=context.Background()client,err:=compute.NewAddressesRESTClient(ctx)iferr!=nil{returnfmt.Errorf("NewAddressesRESTClient: %w",err)}deferclient.Close()addressResource:=&computepb.Address{Name:proto.String(addressName),AddressType:proto.String("EXTERNAL"),Address:proto.String(ephemeralIP),}req:=&computepb.InsertAddressRequest{Project:projectID,Region:region,AddressResource:addressResource,}op,err:=client.Insert(ctx,req)iferr!=nil{returnfmt.Errorf("failed to insert address promoted: %v",err)}// Wait for the operation to completeerr=op.Wait(ctx)iferr!=nil{returnfmt.Errorf("failed to complete promotion operation: %v",err)}fmt.Fprintf(w,"Ephemeral IP %s address promoted successfully",ephemeralIP)returnnil}Java
importcom.google.cloud.compute.v1.Address;importcom.google.cloud.compute.v1.Address.AddressType;importcom.google.cloud.compute.v1.AddressesClient;importcom.google.cloud.compute.v1.InsertAddressRequest;importcom.google.common.collect.Lists;importjava.io.IOException;importjava.util.List;importjava.util.UUID;importjava.util.concurrent.ExecutionException;importjava.util.concurrent.TimeUnit;importjava.util.concurrent.TimeoutException;publicclassPromoteEphemeralIp{publicstaticvoidmain(String[]args)throwsIOException,ExecutionException,InterruptedException,TimeoutException{// TODO(developer): Replace these variables before running the sample.// Project ID or project number of the Google Cloud project you want to use.StringprojectId="your-project-id";// Region where the VM and IP is located.Stringregion="your-region-id";// Ephemeral IP address to promote.StringephemeralIp="your-ephemeralIp";// Name of the address to assign.StringaddressName="your-addressName";promoteEphemeralIp(projectId,region,ephemeralIp,addressName);}// Promote ephemeral IP found on the instance to a static IP.publicstaticList<Address>promoteEphemeralIp(StringprojectId,Stringregion,StringephemeralIp,StringaddressName)throwsIOException,ExecutionException,InterruptedException,TimeoutException{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.try(AddressesClientclient=AddressesClient.create()){AddressaddressResource=Address.newBuilder().setName(addressName).setRegion(region).setAddressType(AddressType.EXTERNAL.name()).setAddress(ephemeralIp).build();InsertAddressRequestaddressRequest=InsertAddressRequest.newBuilder().setRegion(region).setProject(projectId).setAddressResource(addressResource).setRequestId(UUID.randomUUID().toString()).build();client.insertCallable().futureCall(addressRequest).get(30,TimeUnit.SECONDS);returnLists.newArrayList(client.list(projectId,region).iterateAll());}}}Python
importuuidfromgoogle.cloud.compute_v1importAddressesClientfromgoogle.cloud.compute_v1.typesimportAddressdefpromote_ephemeral_ip(project_id:str,ephemeral_ip:str,region:str):""" Promote ephemeral IP found on the instance to a static IP. Args: project_id (str): Project ID. ephemeral_ip (str): Ephemeral IP address to promote. region (str): Region where the VM and IP is located. """addresses_client=AddressesClient()# Create a new static IP address using existing ephemeral IPaddress_resource=Address(name=f"ip-reserved-{uuid.uuid4()}",# new name for promoted IP addressregion=region,address_type="EXTERNAL",address=ephemeral_ip,)operation=addresses_client.insert(project=project_id,region=region,address_resource=address_resource)operation.result()print(f"Ephemeral IP{ephemeral_ip} has been promoted to a static IP.")The external IP address remains attached to the VM even after it hasbeen promoted to a static external IP address. If you need to assign thenewly promoted static external IP address to another resource,unassign the static external IP address from the existing VM.
List static external IP addresses
To list static external IP addresses that you have reserved for yourproject, follow these steps.
Console
In the Google Cloud console, go to theIP addresses page.
ClickExternal IP addresses.
gcloud
Use thegcloud compute addresses list command:
To list all IP addresses, use the following command:
gcloud compute addresses list
To list all global IP addresses, use the following command:
gcloud compute addresses list --global
To list all regional IP addresses in a given region, use the followingcommand:
gcloud compute addresses list \ --regions=REGION
Replace
REGIONwith the region that you want tolist addresses for. You can list addresses of multiple regions byspecifying comma-separated region names:gcloud compute addresses list \ --regions=REGION1,REGION2,..REGION_n_
API
To list regional IPv4 or IPv6 addresses, call the
addresses.listmethod:GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/addresses
Replace the following:
PROJECT_ID: the project ID for this requestREGION: the name of the region for thisrequest
To list all addresses in all regions, call the
addresses.aggregatedListmethod:GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/aggregated/addresses
To list global IPv4 or IPv6 addresses, call the
globalAddresses.listmethod:GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/addresses
Replace the following:
PROJECT_ID: the project ID for this request
Go
import("context""fmt""io"compute"cloud.google.com/go/compute/apiv1""google.golang.org/api/iterator""cloud.google.com/go/compute/apiv1/computepb")// listRegionalExternal retrieves list external IP addresses in Google Cloud Platform region.funclistRegionalExternal(wio.Writer,projectID,regionstring)([]*computepb.Address,error){// projectID := "your_project_id"// region := "europe-west3"ctx:=context.Background()// Create the service client.addressesClient,err:=compute.NewAddressesRESTClient(ctx)iferr!=nil{returnnil,err}deferaddressesClient.Close()// Build the request.req:=&computepb.ListAddressesRequest{Project:projectID,Region:region,}// List the addresses.it:=addressesClient.List(ctx,req)// Iterate over the results.varaddresses[]*computepb.Addressfor{address,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{returnnil,err}addresses=append(addresses,address)}// Print the addresses.fmt.Fprint(w,"Fetched addresses: \n")for_,address:=rangeaddresses{fmt.Fprintf(w,"%s\n",*address.Name)}returnaddresses,nil}// listGlobalExternal retrieves list external global IP addresses in Google Cloud Platform.funclistGlobalExternal(wio.Writer,projectIDstring)([]*computepb.Address,error){// projectID := "your_project_id"ctx:=context.Background()// Create the service client.addressesClient,err:=compute.NewGlobalAddressesRESTClient(ctx)iferr!=nil{returnnil,err}deferaddressesClient.Close()// Build the request.req:=&computepb.ListGlobalAddressesRequest{Project:projectID,}// List the addresses.it:=addressesClient.List(ctx,req)// Iterate over the results.varaddresses[]*computepb.Addressfor{address,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{returnnil,err}addresses=append(addresses,address)}// Print the addresses.fmt.Fprint(w,"Fetched addresses: \n")for_,address:=rangeaddresses{fmt.Fprintf(w,"%s\n",*address.Name)}returnaddresses,nil}Java
importcom.google.cloud.compute.v1.Address;importcom.google.cloud.compute.v1.AddressesClient;importcom.google.cloud.compute.v1.GlobalAddressesClient;importcom.google.cloud.compute.v1.ListAddressesRequest;importcom.google.cloud.compute.v1.ListGlobalAddressesRequest;importcom.google.common.collect.Lists;importjava.io.IOException;importjava.util.List;importjava.util.concurrent.ExecutionException;importjava.util.concurrent.TimeoutException;publicclassListStaticExternalIp{publicstaticvoidmain(String[]args)throwsIOException,ExecutionException,InterruptedException,TimeoutException{// TODO(developer): Replace these variables before running the sample.// Project ID or project number of the Google Cloud project you want to use.StringprojectId="your-project-id";// Region where the VM and IP is located.Stringregion="your-region-id";listStaticExternalIp(projectId,region);}// Lists all static external IP addresses, either regional or global.publicstaticList<Address>listStaticExternalIp(StringprojectId,Stringregion)throwsIOException{// Use regional client if a region is specifiedif(region!=null){// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.try(AddressesClientclient=AddressesClient.create()){ListAddressesRequestrequest=ListAddressesRequest.newBuilder().setProject(projectId).setRegion(region).build();returnLists.newArrayList(client.list(request).iterateAll());}}else{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.try(GlobalAddressesClientclient=GlobalAddressesClient.create()){ListGlobalAddressesRequestrequest=ListGlobalAddressesRequest.newBuilder().setProject(projectId).build();returnLists.newArrayList(client.list(request).iterateAll());}}}}Python
fromtypingimportList,Optionalfromgoogle.cloud.compute_v1.services.addresses.clientimportAddressesClientfromgoogle.cloud.compute_v1.services.global_addressesimportGlobalAddressesClientfromgoogle.cloud.compute_v1.typesimportAddressdeflist_static_ip_addresses(project_id:str,region:Optional[str]=None)->List[Address]:""" Lists all static external IP addresses, either regional or global. Args: project_id (str): project ID. region (Optional[str]): The region of the IP addresses if regional. None if global. Returns: List[Address]: A list of Address objects containing details about the requested IPs. """ifregion:# Use regional client if a region is specifiedclient=AddressesClient()addresses_iterator=client.list(project=project_id,region=region)else:# Use global client if no region is specifiedclient=GlobalAddressesClient()addresses_iterator=client.list(project=project_id)returnlist(addresses_iterator)# Convert the iterator to a list to returnDescribe a static external IP address
To get information about a static external IP address, follow these steps.
Console
In the Google Cloud console, go to theIP addresses page.
ClickExternal IP addresses.
Click the IP address that you want to get more information about.
gcloud
Use thegcloud compute addresses describe command.ReplaceADDRESS_NAME with the name ofthe external IP address that you want to describe.
For a global IPv4 or IPv6 address, use the following command:
gcloud compute addresses describeADDRESS_NAME --global
For a regional IPv4 or IPv6 address, use the following command:
gcloud compute addresses describeADDRESS_NAME --region=REGION
API
To describe a regional IPv4 or IPv6 address, call the
addresses.getmethod:GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/addresses/ADDRESS_NAME
Replace the following:
PROJECT_ID: the project ID for the requestREGION: the name of the region for the requestADDRESS_NAME: the name of the IP address
To describe a global IPv4 or IPv6 address, call the
globalAddresses.getmethod:GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/addresses/ADDRESS_NAME
Replace the following:
PROJECT_ID: the project ID for the requestADDRESS_NAME: the name of the IP address
Go
import("context""fmt""io"compute"cloud.google.com/go/compute/apiv1""cloud.google.com/go/compute/apiv1/computepb")// getExternalAddress retrieves the external IP address of the given address.funcgetRegionalExternal(wio.Writer,projectID,region,addressNamestring)(*computepb.Address,error){// projectID := "your_project_id"// region := "europe-west3"// addressName := "your_address_name"ctx:=context.Background()addressesClient,err:=compute.NewAddressesRESTClient(ctx)iferr!=nil{returnnil,fmt.Errorf("NewAddressesRESTClient: %w",err)}deferaddressesClient.Close()req:=&computepb.GetAddressRequest{Project:projectID,Region:region,Address:addressName,}address,err:=addressesClient.Get(ctx,req)iferr!=nil{returnnil,fmt.Errorf("unable to get address: %w",err)}fmt.Fprintf(w,"Regional address %s has external IP address: %s\n",addressName,address.GetAddress())returnaddress,nil}funcgetGlobalExternal(wio.Writer,projectID,addressNamestring)(*computepb.Address,error){ctx:=context.Background()globalAddressesClient,err:=compute.NewGlobalAddressesRESTClient(ctx)iferr!=nil{returnnil,fmt.Errorf("NewGlobalAddressesRESTClient: %w",err)}deferglobalAddressesClient.Close()req:=&computepb.GetGlobalAddressRequest{Project:projectID,Address:addressName,}address,err:=globalAddressesClient.Get(ctx,req)iferr!=nil{returnnil,fmt.Errorf("unable to get address: %w",err)}fmt.Fprintf(w,"Global address %s has external IP address: %s\n",addressName,address.GetAddress())returnaddress,nil}Java
importcom.google.cloud.compute.v1.Address;importcom.google.cloud.compute.v1.AddressesClient;importcom.google.cloud.compute.v1.GetAddressRequest;importcom.google.cloud.compute.v1.GetGlobalAddressRequest;importcom.google.cloud.compute.v1.GlobalAddressesClient;importjava.io.IOException;importjava.util.concurrent.ExecutionException;importjava.util.concurrent.TimeoutException;publicclassGetStaticIpAddress{publicstaticvoidmain(String[]args)throwsIOException,ExecutionException,InterruptedException,TimeoutException{// TODO(developer): Replace these variables before running the sample.// Project ID or project number of the Google Cloud project you want to use.StringprojectId="your-project-id";// Region where the VM and IP is located.Stringregion="your-region-id";// Name of the address to assign.StringaddressName="your-addressName";getStaticIpAddress(projectId,region,addressName);}// Retrieves a static external IP address, either regional or global.publicstaticAddressgetStaticIpAddress(StringprojectId,Stringregion,StringaddressName)throwsIOException{// Use regional client if a region is specifiedif(region!=null){// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.try(AddressesClientclient=AddressesClient.create()){GetAddressRequestrequest=GetAddressRequest.newBuilder().setProject(projectId).setRegion(region).setAddress(addressName).build();returnclient.get(request);}}else{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.try(GlobalAddressesClientclient=GlobalAddressesClient.create()){GetGlobalAddressRequestrequest=GetGlobalAddressRequest.newBuilder().setProject(projectId).setAddress(addressName).build();returnclient.get(request);}}}}Python
fromtypingimportOptionalfromgoogle.cloud.compute_v1.services.addresses.clientimportAddressesClientfromgoogle.cloud.compute_v1.services.global_addressesimportGlobalAddressesClientfromgoogle.cloud.compute_v1.typesimportAddressdefget_static_ip_address(project_id:str,address_name:str,region:Optional[str]=None)->Address:""" Retrieves a static external IP address, either regional or global. Args: project_id (str): project ID. address_name (str): The name of the IP address. region (Optional[str]): The region of the IP address if it's regional. None if it's global. Raises: google.api_core.exceptions.NotFound: in case of address not found Returns: Address: The Address object containing details about the requested IP. """ifregion:# Use regional client if a region is specifiedclient=AddressesClient()address=client.get(project=project_id,region=region,address=address_name)else:# Use global client if no region is specifiedclient=GlobalAddressesClient()address=client.get(project=project_id,address=address_name)returnaddressRelease a static external IP address
If you no longer need a static external IPv4 or IPv6 address, you can releasethe IP address by deleting the IP address resource.
If you are using the Google Cloud console, you can release a static IP addressonly if it is not being used by another resource.
If you're using the gcloud CLI or API, you can releasean IP address whether or not it's being used by another resource.
If the IP address is not being used by a resource, the IP address isreturned to the pool of available external IP addresses.
If the IP address is being used by a resource, it remains attached to theresource until the resource is deleted.
Console
In the Google Cloud console, go to theIP addresses page.
ClickExternal IP addresses.
Optional: In theFilter field, enter
staticand then selectStatic : Type from the drop-down list.Select the static external IP address that you want to release.
ClickRelease static address.
If you don't see this option, click theMore actions menu() in the top menu bar, and then selectRelease static address from the list.
gcloud
Use thecompute addresses delete command:
gcloud compute addresses deleteADDRESS_NAME
ReplaceADDRESS_NAME with the name of the IPv4 orIPv6 address to release.
API
To release a regional IPv4 or IPv6 address, call the
addresses.deletemethod:DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/addresses/ADDRESS_NAME
Replace the following:
PROJECT_ID: the project ID for this requestREGION: the name of the region for thisrequestADDRESS_NAME: the name of the IP address
To release a global IPv4 or IPv6 address, call the
globalAddresses.deletemethod:DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/addresses/ADDRESS_NAME
Replace the following:
ADDRESS_NAME: the name of the IP addressPROJECT_ID: the project ID for this request
Go
import("context""fmt""io"compute"cloud.google.com/go/compute/apiv1""cloud.google.com/go/compute/apiv1/computepb")// releaseRegionalStaticExternal releases a static regional external IP address.funcreleaseRegionalStaticExternal(wio.Writer,projectID,region,addressNamestring)error{// projectID := "your_project_id"// region := "us-central1"// addressName := "your_address_name"ctx:=context.Background()addressesClient,err:=compute.NewAddressesRESTClient(ctx)iferr!=nil{returnfmt.Errorf("NewAddressesRESTClient: %w",err)}deferaddressesClient.Close()req:=&computepb.DeleteAddressRequest{Project:projectID,Region:region,Address:addressName,}op,err:=addressesClient.Delete(ctx,req)iferr!=nil{returnfmt.Errorf("unable to release static external IP address: %w",err)}iferr=op.Wait(ctx);err!=nil{returnfmt.Errorf("unable to wait for the operation: %w",err)}fmt.Fprintf(w,"Static external IP address released\n")returnnil}// releaseGlobalStaticExternal releases a static global external IP address.funcreleaseGlobalStaticExternal(wio.Writer,projectID,addressNamestring)error{// projectID := "your_project_id"// addressName := "your_address_name"ctx:=context.Background()addressesClient,err:=compute.NewGlobalAddressesRESTClient(ctx)iferr!=nil{returnfmt.Errorf("NewGlobalAddressesRESTClient: %w",err)}deferaddressesClient.Close()req:=&computepb.DeleteGlobalAddressRequest{Project:projectID,Address:addressName,}op,err:=addressesClient.Delete(ctx,req)iferr!=nil{returnfmt.Errorf("unable to release static external IP address: %w",err)}iferr=op.Wait(ctx);err!=nil{returnfmt.Errorf("unable to wait for the operation: %w",err)}fmt.Fprintf(w,"Static external IP address released\n")returnnil}Java
importcom.google.cloud.compute.v1.AddressesClient;importcom.google.cloud.compute.v1.DeleteAddressRequest;importcom.google.cloud.compute.v1.DeleteGlobalAddressRequest;importcom.google.cloud.compute.v1.GlobalAddressesClient;importcom.google.cloud.compute.v1.Operation;importjava.io.IOException;importjava.util.concurrent.ExecutionException;importjava.util.concurrent.TimeUnit;importjava.util.concurrent.TimeoutException;publicclassReleaseStaticAddress{publicstaticvoidmain(String[]args)throwsIOException,ExecutionException,InterruptedException,TimeoutException{// TODO(developer): Replace these variables before running the sample.// Project ID or project number of the Google Cloud project you want to use.StringprojectId="your-project-id";// The region to reserve the IP address in, if regional. Must be None if globalStringregion="your-region =";// Name of the address to release.StringaddressName="your-addressName";releaseStaticAddress(projectId,addressName,region);}// Releases a static external IP address that is currently reserved.// This action requires that the address is not being used by any forwarding rule.publicstaticvoidreleaseStaticAddress(StringprojectId,StringaddressName,Stringregion)throwsIOException,ExecutionException,InterruptedException,TimeoutException{Operationoperation;// Use global client if no region is specifiedif(region==null){// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.try(GlobalAddressesClientclient=GlobalAddressesClient.create()){DeleteGlobalAddressRequestrequest=DeleteGlobalAddressRequest.newBuilder().setProject(projectId).setAddress(addressName).build();operation=client.deleteCallable().futureCall(request).get(30,TimeUnit.SECONDS);}}else{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.try(AddressesClientclient=AddressesClient.create()){DeleteAddressRequestrequest=DeleteAddressRequest.newBuilder().setProject(projectId).setRegion(region).setAddress(addressName).build();operation=client.deleteCallable().futureCall(request).get(30,TimeUnit.SECONDS);}}if(operation.hasError()){System.out.printf("Can't release external IP address '%s'. Caused by : %s",addressName,operation.getError());}System.out.printf("External IP address '%s' released successfully.",addressName);}}Python
fromtypingimportOptionalfromgoogle.cloud.compute_v1.services.addresses.clientimportAddressesClientfromgoogle.cloud.compute_v1.services.global_addressesimportGlobalAddressesClientdefrelease_external_ip_address(project_id:str,address_name:str,region:Optional[str]=None,)->None:""" Releases a static external IP address that is currently reserved. This action requires that the address is not being used by any forwarding rule. Args: project_id (str): project ID. address_name (str): name of the address to release. region (Optional[str]): The region to reserve the IP address in, if regional. Must be None if global. """ifnotregion:# global IP addressclient=GlobalAddressesClient()operation=client.delete(project=project_id,address=address_name)else:# regional IP addressclient=AddressesClient()operation=client.delete(project=project_id,region=region,address=address_name)operation.result()print(f"External IP address '{address_name}' released successfully.")What's next
- Learn how toConfigure static external IP addressesfor a new or existing VM.
- Learn aboutIP address specificationsfor forwarding rules, and how touse forwarding rules, in theForwarding rules overview.
- Learn more aboutIP addresses.
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-17 UTC.