Learn how to locate external and internal IP addresses for your instance.
Before you begin
-
If you haven't already, then 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 to
Compute Engine by selecting one of the following options:
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, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
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, then initialize it by running the following command:
gcloud init
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
Permissions required for this task
To perform this task, you must have the following permissions:
compute.instances.get
on the instance
Viewing IP addresses
You view the internal and external IP addresses for your instance through either the Google Cloud console, the Google Cloud CLI, or REST.
Console
In the Google Cloud console, go to the VM instances page. If the VM instance has an external IP address, it appears under the External IP column. If a VM does not have an external IP address, you can assign one.
gcloud
To view the internal and external IP addresses for your instance
using gcloud compute
, use the
instances list
sub-command.
gcloud compute instances list
Your output should resemble the following:
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS hulk us-central1-c m1-ultramem-160 true 192.0.2.1 RUNNING my-instance us-central1-c e2-standard-2 192.51.100.1 203.224.0.113 RUNNING
To view the internal or external IP address for a specific instance using
gcloud compute
, use the
instances describe
sub-command with a --format
flag to filter the output. For example:
To view the internal IP for a specific instance, run the following command:
gcloud compute instances describe instance-name \ --format='get(networkInterfaces[0].networkIP)' 192.51.100.1
To view the external IP for a specific instance, run the following command:
gcloud compute instances describe instance-name \ --format='get(networkInterfaces[0].accessConfigs[0].natIP)' 203.224.0.113
Replace instance-name
with the name of the instance
whose internal or external IP you want to view.
REST
Make a GET
request to the
instances.get
method.
GET https://compute.googleapis.com/compute/v1/projects/project-id/zones/zone/instances/instance-name
Replace the following:
project-id
: The project ID for this query.zone
: The zone for the instance that you want to query.instance-name
: The name of the instance resource to return.
Your response body resembles the following snippet:
{ ... "networkInterfaces": [ { ... "networkIP": "192.51.100.1", ... "accessConfigs": [ { ... "name": "external-nat", "natIP": "203.224.0.113", ... } ], ... } ], ... }
The following fields contain the required information:
networkIP
is the assigned internal IP address.natIP
is the assigned external IP address.