使用GCP免费额度,重启Compute实例后公网IP未变更致无法访问
Fixing GCP Compute Engine IP Reuse & Access Issues
Hey there! I’ve dealt with this exact scenario a few times when working with GCP’s free tier, so let’s walk through how to get your instances back up and running with a fresh (working) public IP.
First, Diagnose the IP Type
First things first—let’s confirm if your instance is using a temporary (ephemeral) or static IP:
- Head to the GCP Console > Compute Engine > VM Instances. Look at the "External IP" column for your instance; it’ll label the IP as "Ephemeral" or "Static".
- Or use the gcloud CLI to get precise details:
Look for thegcloud compute instances describe YOUR_INSTANCE_NAME --zone YOUR_INSTANCE_ZONEnetworkInterfaces[0].accessConfigs[0].typefield—if it saysSTATIC, that’s why your IP didn’t change on restart (static IPs persist unless you manually remove them). If it’sEPHEMERAL, the IP should’ve rotated, but we’ll force it to refresh.
Force a New Ephemeral IP Assignment
If you’re stuck with an old ephemeral IP that won’t work, here’s how to swap it out:
Option 1: GCP Console Steps
- Stop your instance first (you can’t modify IP settings while it’s running).
- Click the instance name to open its details page, then hit the Edit button at the top.
- Scroll down to the "Network interfaces" section, click the pencil icon next to your primary network interface.
- In the "External IP" dropdown, select Create ephemeral IP (or pick an unused ephemeral IP from the list if available).
- Save your changes, then start the instance again—it should boot up with the new IP.
Option 2: CLI Steps (Faster for Power Users)
- Stop the instance:
gcloud compute instances stop YOUR_INSTANCE_NAME --zone YOUR_INSTANCE_ZONE - Delete the old external IP configuration:
gcloud compute instances delete-access-config YOUR_INSTANCE_NAME --access-config-name "External NAT" --zone YOUR_INSTANCE_ZONE - Add a fresh external IP config:
gcloud compute instances add-access-config YOUR_INSTANCE_NAME --access-config-name "External NAT" --zone YOUR_INSTANCE_ZONE - Start the instance back up:
gcloud compute instances start YOUR_INSTANCE_NAME --zone YOUR_INSTANCE_ZONE
Check for Firewall/Network Blockages
Sometimes the IP itself isn’t the issue—your firewall rules might be blocking access to the new (or old) IP:
- Go to VPC Network > Firewall Rules in the GCP Console.
- Verify you have rules allowing traffic to your instance’s ports (e.g., SSH port 22, HTTP port 80). Make sure the rule’s "Source IP ranges" includes your local machine’s IP (or
0.0.0.0/0for public access, though that’s less secure). - Use the CLI to list rules and confirm:
gcloud compute firewall-rules list
Verify Free Tier IP Quotas
GCP’s free tier has limits on how many external IPs you can use. If you’re hitting the quota, you won’t be able to assign new IPs:
- Go to VPC Network > External IP Addresses in the Console.
- Look for any unassigned ephemeral IPs and delete them (click the 3-dot menu > Delete) to free up quota.
- CLI alternative:
# List all external IPs gcloud compute addresses list # Delete an unused one gcloud compute addresses delete UNUSED_IP_NAME --region YOUR_REGION
内容的提问来源于stack exchange,提问作者vivek saurabh
相关产品推荐
相关产品推荐

