Locating the external and internal IP address for an instance

Learn how to locate external and internal IP addresses for your instance.

Before you begin

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 your IP address through either the Google Cloud Platform Console, the gcloud command-line tool, or the Compute Engine API.

Console

To view the internal and external IP addresses for your instance, go to the VM instances page.

Go to the VM instances page

Screenshot of the VM instances page showing internal and external IPs

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   n1-ultramem-160  true         192.0.2.1                   RUNNING
my-instance       us-central1-c   n1-standard-1                 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
    

where [INSTANCE_NAME] is the name of the instance whose internal or external IP you want to view.

API

Make a GET request to the instances.get method.

https://www.googleapis.com/compute/v1/projects/[PROJECT_ID]/zones/[ZONE]/instances/[INSTANCE_NAME]

where:

  • [ZONE] is the name of the region for this request.
  • [PROJECT_ID] is the project ID for this request.
  • [INSTANCE_NAME] is 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.
¿Te sirvió esta página? Envíanos tu opinión:

Enviar comentarios sobre…

Compute Engine Documentation