# Configuring DNS on hosts

The **DNS** setting has [DNClient](/docs/glossary/dnclient/) point a host's resolver at DNS servers on your Nebula network while the host is connected, so people can reach `web-01.corp.example.com`, or just `web-01`, instead of typing an overlay IP. You choose which domains go to your nameservers, or send them every lookup. When DNClient stops, it removes the DNS settings it applied.

DNS is part of [advanced config](/docs/guides/advanced-host-config/), so you can set it on a host, a tag, or the whole network. For how Nebula applies each field on the host, see the [`dns` reference](https://nebula.defined.net/docs/config/dns/).

## Before you start

The setting applies to macOS and Windows hosts running DNClient 1.0.0 and later. Linux hosts and mobile devices ignore it.

Managed Nebula doesn't answer DNS queries for you. You need:

- A DNS server that answers for your domains and that hosts can reach over Nebula, either at the overlay IP of a host that runs it or at an address behind a [route](/docs/guides/extend-access-beyond-overlay-hosts/). [DNS for Nebula hosts using the API](/blog/dns-for-nebula-hosts-using-the-api/#go-even-further-beyond) shows how to serve your host names from CoreDNS.
- A firewall rule that allows port 53 over UDP and TCP from the hosts that will use the server. Add it to the DNS server's [role or tag](/docs/guides/creating-firewalls-using-roles/), or, for a server behind a route, to the [route](/docs/guides/extend-access-beyond-overlay-hosts/#step-4-configure-the-routers-firewall).

## Setting DNS

Set DNS in the **DNS** section of a host's **Advanced** tab, or add it to a tag or network with **Add config**. [Where advanced config lives](/docs/guides/advanced-host-config/#where-advanced-config-lives) covers each place.

<figure>
  <Image
    src={hostDNSSection}
    alt="The DNS section of a host's Advanced tab. DNS enabled is set to True, DNS nameservers to 100.100.0.53, and DNS search domains to corp.example.com. DNS match domains is empty and Match all domains is unchecked."
    class="screenshot-shadow"
  />
</figure>

- **DNS enabled**: **True** to configure the host's resolver, **False** to leave it alone. Required if any other field is set.
- **DNS nameservers**: the IPv4 or IPv6 addresses of your DNS servers, separated by commas, with no port. At least one is required when DNS is enabled.
- **DNS match domains**: the domains whose lookups go to your nameservers, separated by commas. Leave it empty to use the search domains, or turn on **Match all domains** to send every lookup to your nameservers. DNS needs match domains, search domains, or **Match all domains**.
- **DNS search domains**: domains to try when someone looks up a bare name, such as `web-01`. When you list match domains, each search domain must fall under one of them.

The fields are saved as one setting, so a value on a host or tag replaces the network's DNS entirely instead of merging nameservers or domains. Which value a host gets follows the usual [precedence](/docs/guides/advanced-host-config/#how-values-combine).

DNClient applies a DNS change without a restart. Saving DNS on a tag or network that has hosts still shows the **Restart dnclient** dialog, which DNClient hosts can ignore.

## Common setups

### Resolving your own domain

To send lookups for one internal domain to your DNS server, set **DNS enabled** to **True**, **DNS nameservers** to the server's overlay IP, such as `100.100.0.53`, and **DNS search domains** to `corp.example.com`.

With match domains left empty, `corp.example.com` is also the match domain. Hosts resolve `web-01.corp.example.com` and `web-01` through your server, and every other name as before. Because only your domain depends on the tunnel, this split DNS setup suits laptops that move between networks.

Set it on a tag, such as `dns:corp`, and assign the tag to the hosts that should use it. To cover every host in the network, set it on the network instead.

### Sending every lookup to your DNS server

Turn on **Match all domains** to send all of a host's lookups to your nameservers, for example to apply your own filtering. If those nameservers are reachable only over Nebula, the host can't resolve any name while its tunnel to them is down.

### Turning DNS off for one host

When a tag or the network sets DNS, open a host's **Advanced** tab and set **DNS enabled** to **False**. A host's own value wins, so DNClient leaves that host's DNS alone.

## Checking a host

To confirm the host received the setting, run `dnclient info` and look for the `dns` section. See [Checking a host's values](/docs/guides/advanced-host-config/#checking-a-hosts-values).

For split DNS, you can also check what the operating system is using:

- On macOS, run `scutil --dns`. Your nameservers appear in a resolver entry for each match domain.
- On Windows, run `Get-DnsClientNrptPolicy` in PowerShell. Each match domain has a rule pointing at your nameservers.

If a name doesn't resolve, check that the host can reach the DNS server over Nebula and that the server's firewall rules allow port 53 from the host. Browsers and apps that use their own resolver or encrypted DNS can bypass these settings, so test with a command such as `ping web-01.corp.example.com` too.

## Setting DNS with the API

DNS is the `dns` config override. Its value is an object with `enabled`, `nameservers`, `match_domains`, and `search_domains`, where the last three are arrays. An empty `match_domains` array is the same as **Match all domains**, and leaving `match_domains` out uses the search domains. For example, the split DNS example above on a tag:

```json
{
  "key": "dns",
  "value": {
    "enabled": true,
    "nameservers": ["100.100.0.53"],
    "search_domains": ["corp.example.com"]
  }
}
```

See [Setting advanced config with the API or Terraform](/docs/guides/advanced-host-config/#setting-advanced-config-with-the-api-or-terraform) for the endpoints on each level, and [Config override keys](/docs/api/config-override-keys/#dns) for the value's rules.
