When you build applications on Google Cloud, replacing a virtual machine is a normal part of infrastructure maintenance. You might replace a VM to upgrade its machine type, move to a newer operating system image, recover from a failure, or deploy a new application version.
However, replacing a VM can create a networking problem when other systems depend on its private IP address.
This is especially important when you use Private Service Connect (PSC) interfaces to connect a service producer VPC network to a consumer VPC network. By default, Google Cloud assigns an ephemeral internal IP address to a PSC interface. If you delete or replace the VM, that address is released. The replacement VM can receive a different address, which may break firewall rules, routing configurations, application settings, and other integrations.
Google Cloud supports reserved static internal IP addresses for Private Service Connect interfaces. You can reserve an address from the consumer's network attachment subnet and assign it to a producer VM. The reservation remains available in the producer project even when the VM or interface is deleted.
This makes it possible to replace a VM while retaining the same PSC interface IP address.
In this article, we'll explore how stable IP addresses work with Private Service Connect interfaces, how to reserve and assign an address using the Google Cloud CLI, and how to verify that the address remains available after replacing a VM.
Understanding Private Service Connect Interfaces
Private Service Connect provides private connectivity between service consumers and service producers without requiring direct VPC network peering.
A Private Service Connect interface is a networking option that allows a service producer's VPC network to initiate connections to a consumer's VPC network.
For example, imagine a company that provides a managed data processing service. Its application runs in a producer VPC, but it needs to access databases and internal services hosted in a customer's consumer VPC.
A PSC interface provides that connection while maintaining isolation between the two networks.
The connection involves two important resources:
The consumer creates a network attachment and defines which producers can connect to it. The producer creates a VM with a PSC interface that references the network attachment.
When the connection is accepted, Google Cloud assigns an internal IP address from the network attachment's subnet to the PSC interface.
Why the default IP address can cause problems
By default, Google Cloud dynamically allocates an ephemeral internal IP address when the PSC interface connects to the network attachment.
Consider a producer VM with the following configuration:
Resource | Value |
|---|
VM name | processing-vm |
Producer project | producer-project |
Consumer project | consumer-project |
Network attachment | consumer-attachment |
PSC interface IP | Dynamically allocated |
Region | us-central1 |
Suppose the PSC interface receives the address 192.168.10.5.
The application might use this address in firewall rules, service configurations, or internal monitoring systems.
If the VM is deleted and recreated, Google Cloud releases the ephemeral address. The replacement VM can receive another address, such as 192.168.10.8.
The application may then lose connectivity if other systems still expect 192.168.10.5.
This is the problem that reserved static internal IP addresses solve.
How Stable IP Addresses Work
A stable PSC interface IP address is a static internal address reserved in the producer project from the subnet associated with the consumer's network attachment.
The address is allocated from the consumer's subnet, but the address resource belongs to the producer project.
This distinction is important because the producer manages the reservation while the consumer controls the network attachment and its subnet.
The process has two main stages.
Reserve the address
The producer creates a regional internal address resource and references the consumer's network attachment.
Google Cloud allocates an available address from the network attachment's subnet and reserves it for the producer project.
The address can be assigned to a PSC interface as its primary IPv4 or IPv6 address. An IPv4 reservation can also be used as an alias IP address when the application requires that configuration.
Assign the address to the PSC interface
When creating the VM, the producer references the reserved address resource in the PSC network interface configuration.
The interface uses that address instead of requesting a new ephemeral address.
If the VM is deleted, the reservation remains in the producer project. A replacement VM can reference the same address resource.
The lifecycle looks like this:
Consumer Project
|
v
Network Attachment
|
v
Consumer Subnet
|
| Allocate internal IP
v
Producer Project
|
v
Reserve Static IP Address
|
v
Assign Address to PSC Interface
|
v
+-------------------------+
| Producer VM |
| |
| PSC Interface |
| IP: 192.168.10.5 |
+-------------------------+
|
| Delete VM
v
Reserved IP remains available
|
v
Create Replacement VM
|
v
Assign the same reservation
|
v
+-------------------------+
| Replacement VM |
| |
| PSC Interface |
| IP: 192.168.10.5 |
+-------------------------+
The replacement VM receives the same reserved address, so systems that depend on that address do not need to be reconfigured.
Prerequisites
Before configuring a stable PSC interface IP, make sure the environment meets the following requirements.
Network attachment
The consumer must provide a network attachment in the region where the producer VM will be deployed.
The network attachment must have a subnet with enough available addresses. The producer must also be authorized to connect to the attachment.
If the network attachment uses manual connection acceptance, the consumer must add the producer project to its accept list.
Producer project permissions
The producer needs the permissions required to create Compute Engine instances, manage internal addresses, and create PSC interfaces.
The predefined Compute Instance Admin (v1) and Compute Network Admin roles include permissions relevant to these operations. For production environments, consider using custom roles with only the required permissions.
Compatible VM configuration
A VM with a virtual PSC interface must have at least two network interfaces:
The producer subnet must be in the same region as the network attachment.
The examples in this article use an IPv4 PSC interface. The network attachment's subnet and the selected interface stack type must support the chosen IP version.
Step 1: Set Up the Environment
Start by defining the project and network configuration.
The following example uses a producer project named producer-project and a consumer project named consumer-project.
export PRODUCER_PROJECT="producer-project"
export CONSUMER_PROJECT="consumer-project"
export REGION="us-central1"
export ZONE="us-central1-a"
export PRODUCER_SUBNET="producer-subnet"
export ATTACHMENT_NAME="consumer-attachment"
export VM_NAME="processing-vm"
export ADDRESS_NAME="processing-vm-psc-ip"
Set the active project:
gcloud config set project "$PRODUCER_PROJECT"
Enable the Compute Engine API if it is not already enabled:
gcloud services enable compute.googleapis.com \
--project="$PRODUCER_PROJECT"
You also need the full URI of the consumer's network attachment.
export ATTACHMENT_URI="projects/${CONSUMER_PROJECT}/regions/${REGION}/networkAttachments/${ATTACHMENT_NAME}"
The network attachment must already exist. Its subnet supplies the address range from which the static IP is allocated.
Step 2: Reserve a Static Internal IP Address
Use the gcloud compute addresses create command to reserve an internal address from the network attachment's subnet.
gcloud compute addresses create "$ADDRESS_NAME" \
--project="$PRODUCER_PROJECT" \
--region="$REGION" \
--ip-version=IPV4 \
--network-attachment="$ATTACHMENT_URI"
This command creates a regional address resource in the producer project.
The network-attachment option tells Google Cloud to allocate the address from the subnet associated with the consumer's network attachment.
You do not need to specify an IP address manually. Google Cloud selects an available address from the network attachment's subnet.
Verify the reservation
After creating the address, describe it:
gcloud compute addresses describe "$ADDRESS_NAME" \
--project="$PRODUCER_PROJECT" \
--region="$REGION"
The output includes the reserved address and its resource configuration.
For example, the assigned address might be:
address: 192.168.10.5
addressType: INTERNAL
ipVersion: IPV4
name: processing-vm-psc-ip
region: us-central1
The actual address depends on the available range in the consumer's subnet.
You can also inspect the consumer's network attachment to see its connection endpoints. A reserved address that is not currently assigned to a PSC interface appears with the status RESERVED.
Step 3: Create a VM With the Reserved PSC IP Address
Now create a producer VM and assign the reserved address to its PSC interface.
The VM needs a standard network interface for its producer-side network and a separate PSC interface for the consumer connection.
Use the following command:
gcloud compute instances create "$VM_NAME" \
--project="$PRODUCER_PROJECT" \
--zone="$ZONE" \
--machine-type=e2-standard-2 \
--image-project=debian-cloud \
--image-family=debian-12 \
--network-interface="subnet=${PRODUCER_SUBNET},no-address" \
--network-interface="network-attachment=${ATTACHMENT_URI},private-network-ip=projects/${PRODUCER_PROJECT}/regions/${REGION}/addresses/${ADDRESS_NAME}"
The important part is the second network-interface argument:
network-attachment=ATTACHMENT_URI,
private-network-ip=ADDRESS_RESOURCE_URI
The network-attachment value identifies the consumer's network attachment.
The private-network-ip value references the static IPv4 address resource created in the previous step.
This tells Google Cloud to assign the reserved address to the PSC interface rather than dynamically allocating an ephemeral address.
The example uses Debian 12 and an E2 machine type. You can select a different supported machine type and operating system image based on your workload.
If the network attachment requires manual acceptance, the consumer must authorize the connection before the interface can be created successfully.
Verify the VM interface
After the VM is created, inspect its network configuration:
gcloud compute instances describe "$VM_NAME" \
--project="$PRODUCER_PROJECT" \
--zone="$ZONE"
Review the networkInterfaces section.
Confirm that the PSC interface references the expected network attachment and that its assigned address matches the reserved address.
You can also describe the address resource again. Its status should indicate that it is in use when attached to the interface.
Step 4: Test the PSC Connection
Assigning a stable IP address does not automatically configure application routing.
You must configure the producer VM's operating system and network routes so that traffic uses the correct interface.
After creating the PSC interface, review the routing configuration.
For Linux workloads, inspect the available interfaces and routes:
ip address
ip route
ip rule
The output helps you identify the PSC interface, its assigned address, and the routes used by the operating system.
Configure routing according to the consumer network's requirements. For multi-interface VMs, do not assume that the default route automatically uses the PSC interface.
Also verify that the consumer's firewall rules allow the required traffic and that the producer VM has the necessary application permissions.
Test connectivity to an authorized destination in the consumer VPC.
For example:
ping -c 4 10.20.0.10
Replace the example destination with a reachable address in the consumer network. ICMP might be blocked by firewall rules, so use an application-level test when ping is not permitted.
Step 5: Replace the VM Without Losing the IP Address
This is where the stable address reservation becomes useful.
Suppose the original VM needs to be replaced because of an operating system upgrade or a change in machine configuration.
The reserved address remains available even after the VM is deleted.
Delete the original VM
Delete the VM without deleting the reserved address resource:
gcloud compute instances delete "$VM_NAME" \
--project="$PRODUCER_PROJECT" \
--zone="$ZONE"
The VM and its PSC interface are removed.
However, the static internal address resource remains in the producer project. It is not automatically released when the VM is deleted.
The network attachment's connection endpoint returns to the RESERVED state while the address is not assigned to an active interface.
Create the replacement VM
Create the replacement VM using the same reserved address resource.
For example, you can use a newer machine type while keeping the PSC address unchanged:
gcloud compute instances create processing-vm \
--project="$PRODUCER_PROJECT" \
--zone="$ZONE" \
--machine-type=e2-standard-4 \
--image-project=debian-cloud \
--image-family=debian-12 \
--network-interface="subnet=${PRODUCER_SUBNET},no-address" \
--network-interface="network-attachment=${ATTACHMENT_URI},private-network-ip=projects/${PRODUCER_PROJECT}/regions/${REGION}/addresses/${ADDRESS_NAME}"
The replacement VM uses the same network attachment and address resource.
Google Cloud assigns the previously reserved address to the new PSC interface.
The result is that the replacement VM retains the same PSC interface IP address.
Verify the address after replacement
Describe the new VM:
gcloud compute instances describe processing-vm \
--project="$PRODUCER_PROJECT" \
--zone="$ZONE"
Confirm that the PSC interface uses the original reserved address.
You can also inspect the address resource:
gcloud compute addresses describe "$ADDRESS_NAME" \
--project="$PRODUCER_PROJECT" \
--region="$REGION"
The address should now be in use again.
This process allows you to replace the VM without changing the IP address that consumer-side systems use to communicate with the PSC interface.
Using Stable Addresses With Dynamic PSC Interfaces
Google Cloud supports two types of PSC interfaces: virtual and dynamic.
A virtual PSC interface is added when the VM is created and is removed when the VM is deleted.
A dynamic PSC interface can be added to or removed from an existing Linux VM without restarting the VM. It uses a VLAN-based interface and requires a parent network interface.
Both interface types can use reserved static internal addresses.
For example, a dynamic PSC interface can be created with a reserved IPv4 address by using the network-interfaces add command:
gcloud compute instances network-interfaces add processing-vm \
--project="$PRODUCER_PROJECT" \
--zone="$ZONE" \
--vlan=2 \
--parent-nic-name=nic0 \
--network-attachment="$ATTACHMENT_URI"
This command adds a dynamic PSC interface, but it does not assign the reserved address by itself.
For dynamic interfaces, use the supported interface configuration options to assign the reserved address. The same address resource can be referenced through the private-network-ip option when configuring the interface at VM creation time. For existing VMs, follow the current CLI or API procedure for updating the dynamic interface configuration.
Choose the interface type based on the workload:
Area | Virtual PSC interface | Dynamic PSC interface |
|---|
Creation | During VM creation | Can be added to an existing VM |
Removal | Removed with the VM | Can be removed independently |
Guest OS | Linux and Windows | Linux |
VLAN configuration | Not required | Required |
Best suited for | Stable interface configuration | Dynamic connection management |
For a VM that needs a stable PSC connection throughout its lifecycle, a virtual interface is often straightforward. Dynamic interfaces are useful when the application needs to add or remove consumer connections without restarting the VM.
Stable Primary IP vs. Alias IP Address
A reserved address can be assigned to a PSC interface in different ways.
The primary IP address identifies the PSC interface itself. An alias IP address provides an additional IP range associated with the interface.
These options serve different networking requirements.
Area | Primary PSC IP | Alias IP |
|---|
Purpose | Identifies the PSC interface | Provides additional IP addresses or ranges |
Allocation | From the network attachment subnet | From the same subnet's primary IP range |
Assignment | Uses the reserved address resource | Uses the reserved address or range in alias configuration |
Common use | Stable interface identity | Multiple service addresses behind one interface |
For example, a network appliance might need one stable interface address and additional addresses for different services. In that case, alias IP ranges can be useful.
When using alias IP ranges, coordinate the address allocation with the consumer network administrator. Make sure the subnet has enough available addresses for the interface's primary address and all requested alias ranges.
Common Mistakes to Avoid
Using an ephemeral address
Creating a PSC interface without specifying a reserved address allows Google Cloud to allocate an ephemeral address.
That address can change when the VM or interface is deleted and recreated.
If other systems depend on the address, reserve a static internal address before creating the VM.
Reserving an address from the wrong subnet
The address must be allocated from the subnet associated with the consumer's network attachment.
Do not reserve an ordinary internal address from the producer's own subnet and expect it to work as the PSC interface address.
Use the network-attachment option when creating the address resource.
Deleting the reservation with the VM
The reserved address is a separate resource from the VM.
When replacing the VM, delete only the VM. Keep the address resource so that the replacement can reuse it.
Recreating the VM without the address reference
A replacement VM must explicitly reference the existing address resource in its PSC interface configuration.
If you omit the private-network-ip option, Google Cloud can allocate an ephemeral address instead.
Ignoring network attachment authorization
A reserved address does not bypass the consumer's connection authorization policy.
If the network attachment uses manual acceptance, the producer project must be authorized. Otherwise, VM creation or interface connection can fail.
Forgetting operating system routing
A successfully created PSC interface does not guarantee that application traffic will use it.
Configure routes, firewall rules, and application settings for the additional interface. This is especially important when the VM has multiple network interfaces.
Monitoring and Troubleshooting
When a stable PSC interface does not work as expected, investigate the address reservation, network attachment, VM configuration, and operating system routing separately.
Check the address resource
Run:
gcloud compute addresses describe "$ADDRESS_NAME" \
--project="$PRODUCER_PROJECT" \
--region="$REGION"
Confirm that the address exists and that its configuration references the expected network attachment.
Check the network attachment
Inspect the network attachment in the consumer project.
gcloud compute network-attachments describe "$ATTACHMENT_NAME" \
--project="$CONSUMER_PROJECT" \
--region="$REGION"
Review the subnet, connection endpoints, and connection status.
A RESERVED endpoint indicates that an address is reserved but is not currently assigned to an active PSC interface. An ACCEPTED endpoint indicates that the connection has been accepted.
Check the VM configuration
Run:
gcloud compute instances describe processing-vm \
--project="$PRODUCER_PROJECT" \
--zone="$ZONE"
Verify the PSC interface's network attachment and IP address.
If the interface is missing or has an unexpected address, check whether the VM was created with the correct address resource URI.
Check firewall and routing rules
If the address is correct but traffic does not reach the consumer network, review the producer and consumer firewall rules, guest operating system routes, and application listening addresses.
For multi-NIC VMs, inspect route selection carefully. An incorrect default route or policy rule can send traffic through the wrong interface.
Best Practices for Production Environments
Reserve the PSC interface IP before creating the VM. This avoids depending on an automatically allocated ephemeral address.
Keep the reserved address resource separate from the VM lifecycle. Do not delete it as part of routine VM replacement.
Store the address resource name and network attachment URI in infrastructure configuration so that replacement deployments can reuse them.
Use infrastructure-as-code templates to make VM recreation repeatable. Ensure the template references the existing address resource instead of creating a new one each time.
Coordinate with the consumer network administrator before changing or replacing network attachments.
Configure and test guest operating system routing for every PSC interface.
Monitor network attachment connection endpoints and address resource status during maintenance.
Test the replacement procedure in a non-production environment before using it for critical services.
Keep independent application backups and recovery procedures. A stable IP address preserves network identity, not application data.
Release unused address reservations deliberately. Do not delete an address resource while a VM is actively using it unless you intend to change the interface's address behavior.
Advantages and Limitations
Advantages
Preserves the PSC interface IP address when a VM or interface is deleted and replaced.
Reduces the need to update consumer-side firewall rules and application configurations.
Supports primary IPv4 and IPv6 addresses, subject to network attachment compatibility.
Allows reserved IPv4 addresses to be used as alias IP addresses.
Keeps the address reservation in the producer project independently of the VM lifecycle.
Makes infrastructure replacement easier to automate.
Limitations
The producer must have an authorized connection to the consumer's network attachment.
The reserved address must come from the network attachment's subnet.
The VM must be configured to reference the reservation when the interface is created.
The address becomes unusable if the consumer deletes its project, replaces the network attachment's subnet, or removes the producer's authorization to use the network attachment.
Stable IP allocation does not automatically configure guest operating system routing or firewall rules.
A stable address does not provide application-level high availability or data replication.
Summary
Private Service Connect interfaces provide private connectivity from producer VPC networks to consumer VPC networks. However, their default ephemeral IP allocation can create problems when a producer VM is deleted or replaced.
Google Cloud solves this problem by allowing producers to reserve static internal IP addresses from the subnet associated with a consumer's network attachment. The producer can assign that reserved address to a PSC interface and reuse it when creating a replacement VM.
The important part is to manage the address reservation independently from the VM. During replacement, delete the old VM without deleting the reserved address, then create the new VM using the same address resource and network attachment.
This approach is useful for stateful services, managed network appliances, storage systems, and other applications where consumer-side configurations depend on a predictable private IP address.
A stable PSC IP does not replace routing, firewall configuration, backups, or application-level recovery. It provides a consistent network identity that makes VM maintenance and replacement easier to manage.
Google CloudPrivate Service Connectstatic internal IP addressesPSC interfacesVM replacementnetwork attachments
Join the conversation! Your thoughts help the community grow.