---
title: luna domains
description: Add a domain of your own to an environment, check its DNS records, give it a certificate and remove it.
related:
  - /http/use-your-own-domain
  - /http/serve-http-routes
---

`luna domains` adds domains of your own to an environment. Its HTTP routes are served there once the domain's DNS records prove it yours.

```bash
luna domains add shop.example.com
```

## Reference

```bash
luna domains <COMMAND>
```

Every subcommand acts on one environment, and takes these options.

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `--dir <DIR>` | path | `.` | The app's folder. Its env file names the project and environment. |
| `--env <ENV>` | text | `LUNA_ENV`, then `production` | The environment, by name. |
| `--project <PROJECT>` | text | `LUNA_PROJECT` | The project, by name or as `organisation/project`. |
| `--tenant <TENANT>` | text | The environment's own | A tenant added to the environment, by name. |
| `--token <TOKEN>` | text | `LUNA_TOKEN`, then your login | An API token or account key to act with. |

### luna domains add

Adds a domain and prints the DNS records to create.

```bash
luna domains add [OPTIONS] <NAME>
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `<NAME>` | text | Required | The domain, such as `shop.example.com`. |
| `--json` | flag | Off | Prints the answer as JSON. |

The records are a `CNAME` on the domain, which sends its requests to Luna, and a `TXT` on `_luna.<NAME>`, which proves the domain yours. For a domain that cannot have a `CNAME`, create the `TXT` record and point the domain's `A` records at the addresses of the `CNAME`'s target.

### luna domains list

Lists the environment's domains, with each one's state, when its certificate runs out and when it was added.

```bash
luna domains list [OPTIONS]
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `--json` | flag | Off | Prints the answer as JSON. |

### luna domains verify

Looks up a domain's DNS records now, rather than at Luna's next check, and says where it stands.

```bash
luna domains verify [OPTIONS] <NAME>
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `<NAME>` | text | Required | The domain. |
| `--json` | flag | Off | Prints the answer as JSON. |

### luna domains remove

Removes a domain. Its requests stop reaching the environment, and its certificate is deleted.

```bash
luna domains remove [OPTIONS] <NAME>
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `<NAME>` | text | Required | The domain. |
| `--yes` | flag | Off | Removes it without asking first. |

### luna domains certificate

Serves a certificate you supply for a verified domain.

```bash
luna domains certificate [OPTIONS] --cert <CERT> --key <KEY> <NAME>
```

| Option | Type | Default | Does |
| --- | --- | --- | --- |
| `<NAME>` | text | Required | The domain. |
| `--cert <CERT>` | path | Required | The certificate chain, as PEM. |
| `--key <KEY>` | path | Required | The certificate's private key, as PEM. |

## Good to know

A domain is in one of four states.

| State | Means |
| --- | --- |
| `pending` | Luna is waiting for its DNS records |
| `verified` | Its records prove it yours. It is served over HTTP, and over HTTPS once it has a certificate |
| `active` | Verified, with a certificate |
| `failed` | Verified, and getting a certificate failed. Luna tries again |

- Luna checks a pending domain's records by itself, less often as the domain ages. `luna domains verify` checks now.
- Luna gets a certificate for a verified domain and renews it. A certificate you supply is replaced by one Luna gets when yours is close to running out.

## Examples

### Add a domain

```bash
luna domains add shop.example.com --env production
```

### Check a domain after creating its records

```bash
luna domains verify shop.example.com --env production
```

### Remove a domain from a script

```bash
luna domains remove shop.example.com --env production --yes
```
