> The full list of articles is in [llms.txt](https://docs.f3cloud.com/llms.txt). Every page has a Markdown version: add .md to its address. This page as Markdown: [https://docs.f3cloud.com/en/network/nslookup-dig.md](https://docs.f3cloud.com/en/network/nslookup-dig.md).

# The nslookup and dig commands – how to check a domain's DNS records

The nslookup and dig commands for checking DNS. How to find a domain's IP address, view MX, TXT and NS records, query a specific DNS server, check the reverse PTR record and walk the whole chain of servers with dig +trace. For Linux, macOS and Windows.

You changed a record at your registrar, but the site still opens from the old server. Mail to your domain does not arrive, or a service asks you to verify the domain with a TXT record and insists it cannot see it. In all of these cases you need to ask DNS directly what it is answering right now. There are two commands for this, **nslookup** and **dig**. In this article we look at how they differ and learn to view records of different types, query a specific DNS server and walk the whole chain from the root servers to the answer. All examples were run on a test server with Debian 12.

***

## Why DNS answers can differ

When you ask DNS for a domain's address, the answer almost never comes directly from the server that is responsible for that domain. Your computer contacts its resolver, for example your provider's server or the public `1.1.1.1`, and the resolver either returns an answer from its memory or walks the chain. First it asks a root server, which points it to the servers of the zone, for example `.com`, and they in turn point it to the domain's own NS servers, where the records are actually stored. This chain is covered in detail in the article about [pointing a domain to a VPS](https://docs.f3cloud.com/en/vps/domain-to-vps.md).

It follows from this design that different resolvers can give different answers at the same moment. One has already received the new record, while another is still returning the old one from its memory until the record's storage time, the TTL, runs out. That is why, when checking, it is useful to compare the answers of several resolvers and, if you need to be completely sure, to ask the domain's NS server directly. Both commands can do this, and dig can also walk the whole chain by itself and show which server answered what.

The difference between the commands is mostly a matter of convenience. **nslookup** is available almost everywhere, including Windows, and prints the answer in a simple form. **dig** comes with Linux and macOS, shows the answer in more detail, with the TTL and service fields, and is handier for scripts. On Debian and Ubuntu both commands are installed with a single package.

```bash
apt install -y dnsutils
```

***

## 1. Find out a domain's IP address

```bash
# Detailed dig answer, only the answer section
dig example.com +noall +answer

# Only the addresses, nothing extra
dig example.com +short

# The same with nslookup, works in Windows too
nslookup example.com
```

The number in the second column of the dig answer is the remaining TTL in seconds, that is, how much longer the resolver will remember this answer. IPv6 addresses are checked the same way with the `AAAA` type, for example `dig example.com AAAA +short`.

***

## 2. View records of other types

The record type goes after the domain name in dig or into the `-type=` parameter in nslookup.

```bash
# Mail servers of the domain, the number before the name is the priority
dig gmail.com MX +short

# TXT records, this is where SPF and service verification codes are kept
dig example.com TXT +short

# NS servers that serve the domain
dig example.com NS +short

# Reverse PTR record, which domain an IP address has
dig -x 1.1.1.1 +short
```

<figure><img src="https://docs.f3cloud.com/img/dig-record-types.png" alt="dig answers for A, MX and TXT records, a reverse PTR record and a query to 8.8.8.8"><figcaption><p>Records of different types in one window</p></figcaption></figure>

In nslookup the same queries look like this.

```bash
nslookup -type=mx gmail.com
nslookup -type=txt example.com
nslookup -type=ns example.com
```

<figure><img src="https://docs.f3cloud.com/img/nslookup-mx.png" alt="Output of nslookup -type=mx gmail.com with the list of mail servers"><figcaption><p>nslookup shows the same MX records in a different form</p></figcaption></figure>

***

## 3. Query a specific DNS server

To find out what a particular resolver or the domain's own NS server answers, put it after `@` in dig or as the last parameter in nslookup.

```bash
# Google and Cloudflare public resolvers
dig @8.8.8.8 example.com +short
dig @1.1.1.1 example.com +short

# The domain's own NS server, an answer without cache
dig @elliott.ns.cloudflare.com example.com +short

# The same with nslookup
nslookup example.com 8.8.8.8
```

If the domain's NS server already returns the new record but the public resolvers do not yet, you did everything right, and all that is left is to wait until the TTL of the old answer runs out.

***

## 4. Walk the whole chain with dig +trace

The `+trace` parameter makes dig skip the resolver and walk the path by itself, starting from the root servers. This way you can see who is responsible for the domain at each step.

```bash
dig +trace example.com
```

The full output is long, so for the screenshot we kept only the lines with the steps and the records found.

<figure><img src="https://docs.f3cloud.com/img/dig-trace.png" alt="Output of dig +trace example.com with answers from a root server, a com zone server and a Cloudflare NS server"><figcaption><p>A root server, a .com zone server and the domain's NS server in turn</p></figcaption></figure>

The **Received … from** lines show which server answered at each step. Here the root server `e.root-servers.net` referred the query to the `.com` zone servers, the `c.gtld-servers.net` server reported that the domain is served by Cloudflare, and the NS server `elliott.ns.cloudflare.com` returned the addresses. If the chain breaks, you can see at which step. For example, this happens if the registrar lists NS servers that know nothing about the domain.

***

## Frequently asked questions

<details>

<summary>dig: command not found</summary>

The command is part of the `dnsutils` package. Install it with `apt install -y dnsutils`. In our Debian 12 image this package is already installed.

</details>

<details>

<summary>The answer shows status: NXDOMAIN</summary>

There is no such name in DNS. Check the spelling of the domain and make sure the record was created for the right name, for example separately for `www`. If the domain has just been registered, check its NS servers with `dig example.com NS +short`.

</details>

<details>

<summary>The answer is empty, but there is no error</summary>

The domain exists, but it has no record of the requested type. For example, the domain has an A record but no MX record. Check that the record was created with the right type.

</details>

<details>

<summary>A new record is visible on one resolver but not on another</summary>

The second resolver is still keeping the old answer. Look at the TTL in the output of `dig +noall +answer`, it is the time in seconds until the update. You can clear the DNS cache on your own computer. In Windows this is done with the `ipconfig /flushdns` command.

</details>

***

## Our resources

**Telegram channel:** [https://t.me/f3cloud_news](https://t.me/f3cloud_news)\
**F3 Cloud:** [https://f3cloud.com](https://f3cloud.com/en)
