This document guides you on how to list all previously created public and
private DNS zones in Google Distributed Cloud (GDC) air-gapped.

## Before you begin

To list DNS zones in GDC, you must have the following:

- The necessary identity and access roles. To list DNS records for your project, ask your **IAM Project Admin** to grant you the **Managed DNS Project Viewer** (`managed-dns-project-viewer`) role.
- To use the gdcloud CLI, ensure you have it installed. For more information, see [Install the gdcloud CLI](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/resources/gdcloud-install.md.txt).
- If you are using `kubectl`, a kubeconfig file for the global API server. If you have not yet generated this file, see [Sign in](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/platform/pa-user/iam/sign-in.md.txt#global-resources-kubeconfig). For more information, see [Global and zonal API servers](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/resources/multi-zone/api-servers.md.txt).

## List public or private DNS zones

You can list public or private DNS zones using the gdcloud CLI or the Kubernetes API.

### gdcloud

To list all DNS zones in a project, use the
[`gdcloud dns managed-zones list`](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/resources/gdcloud-reference/gdcloud-dns-managed-zones-list.md.txt)
command:

```bash
gdcloud dns managed-zones list \
    [--project=PROJECT_NAMESPACE]
```

To fetch a single DNS zone by name, use the
[`gdcloud dns managed-zones describe`](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/resources/gdcloud-reference/gdcloud-dns-managed-zones-describe.md.txt)
command:

```bash
gdcloud dns managed-zones describe DNS_ZONE_NAME \
    [--project=PROJECT_NAMESPACE]
```

Replace the following:

- `DNS_ZONE_NAME`: the name of your DNS zone to fetch.
- `PROJECT_NAMESPACE`: the namespace of your project. This flag is optional if you have set a default project globally using `gdcloud config set project`.

### API

Use the Kubernetes API in GDC to list public and private DNS zones.

To fetch a single DNS zone by name:

```yaml
kubectl --kubeconfig GLOBAL_API_SERVER get manageddnszones.networking.global.gdc.goog/v1 DNS_ZONE_NAME -n PROJECT_NAMESPACE
```

To list all DNS zones in a project:

```yaml
kubectl --kubeconfig GLOBAL_API_SERVER get manageddnszones.networking.global.gdc.goog/v1 -n PROJECT_NAMESPACE
```

Replace the following:

- `GLOBAL_API_SERVER`: the global API server's kubeconfig path. For more information, see [Global and zonal API servers](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/resources/multi-zone/api-servers.md.txt). If you have not yet generated a kubeconfig file for the API server, see [Sign in](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/platform/pa-user/iam/sign-in.md.txt) for details.
- `DNS_ZONE_NAME`: the name of your DNS zone to fetch.
- `PROJECT_NAMESPACE`: the namespace of your project.