# DNS Troubleshooting

# Common Issues and Commands

DNS is an important part of how websites and web applications work.

But sometimes, a domain does not resolve correctly, a website points to an old IP address, or a custom domain stops working after a DNS configuration change.

These problems can be difficult to understand without knowing how to troubleshoot DNS.

In this article, we will explore common DNS problems and learn how to investigate them using practical commands and tools.

## 1\. Common DNS Problems

Before troubleshooting DNS, let's understand some common problems developers may face.

### Domain Not Found

A domain or subdomain may not have the required DNS Record.

For example, you may have configured `example.com` but forgotten to add a record for `www.example.com`.

This can cause DNS resolution errors.

### Wrong IP Address

Your domain may resolve successfully, but it can point to the wrong IP address.

This can happen when an A Record contains an outdated or incorrect IP address.

### Old DNS Records in Cache

After changing a DNS Record, some DNS Resolvers may still return the previous value.

This happens because they may have the old record stored in their cache until its TTL expires.

### Incorrect Nameservers

Your domain may use Nameservers that do not contain the DNS Records you configured.

For example, you may add records in Cloudflare while your domain still points to another DNS Provider.

### DNS Server Problems

Sometimes, a DNS Resolver or an authoritative Nameserver may fail to respond correctly.

This can cause DNS queries to time out or return server errors.

## 2\. Understanding Common DNS Errors

![](https://cdn.hashnode.com/uploads/covers/6ab88c552e6a138abf7988a0/5c6ab5ed-9457-4d3f-bd72-da410b4055b9.jpg align="center")

When a DNS query fails, the response can help you understand the problem.

Here are some common DNS response codes:

| Response | Meaning |
| --- | --- |
| NXDOMAIN | The requested domain name does not exist |
| SERVFAIL | The DNS server failed to complete the query |
| NOERROR | The query completed successfully, but the requested record may not exist in the answer |
| REFUSED | The DNS server refused the query |

### NXDOMAIN

NXDOMAIN <mark>means that the requested domain name does not exist</mark> according to the DNS response.

Possible causes include:

- Incorrect domain spelling.
- A missing domain or subdomain.
- An incorrect DNS configuration.
- A cached negative response.

### SERVFAIL

SERVFAIL means that the DNS Resolver could not complete the query successfully.

Possible causes include:

- Problems with authoritative Nameservers.
- DNSSEC validation failures.
- DNS server configuration problems.

### NOERROR with No Answer

Sometimes, a domain exists, but the requested record type is not available.

For example, a domain may have an A Record but no AAAA Record.

The DNS response can return NOERROR without an answer for the requested record type.

This situation is sometimes called NODATA.

### DNS Timeout

A timeout happens when a DNS query does not receive a response within the expected time.

Possible causes include:

- An unavailable DNS server.
- Network connectivity problems.
- Firewall rules blocking DNS traffic.
- DNS server configuration problems.

## 3\. Using nslookup to Check DNS Records

`nslookup` is a command-line tool that helps you query DNS information.

It is available on Windows, macOS, and Linux.

### Check a Domain

```bash
nslookup example.com
```

This returns DNS resolution information for the domain using your configured DNS Resolver.

### Check an A Record

```bash
nslookup -type=A example.com
```

This checks the IPv4 record.

### Check an MX Record

```bash
nslookup -type=MX example.com
```

This checks the mail servers configured for the domain.

### Check Nameservers

```bash
nslookup -type=NS example.com
```

This displays the domain's NS Records.

You can also query a specific DNS Resolver:

```bash
nslookup example.com 1.1.1.1
```

This sends the query to Cloudflare's public DNS Resolver.

## 4\. Using dig to Troubleshoot DNS

`dig` (Domain Information Groper) is a command-line tool used to query DNS servers and inspect DNS responses.

It is commonly available on Linux and macOS. On Windows, you can use it through environments such as WSL or install a DNS utilities package.

### Check an A Record

```bash
dig example.com A
```

This returns detailed information about the A Record query.

To display only the returned IP address:

```bash
dig example.com A +short
```

### Check an MX Record

```bash
dig example.com MX +short
```

This displays the mail servers configured for the domain.

### Check Nameservers

```bash
dig example.com NS +short
```

This displays the authoritative Nameserver records returned for the domain.

### Query a Specific DNS Resolver

```bash
dig @1.1.1.1 example.com A
```

This sends the query to Cloudflare's DNS Resolver.

You can compare it with Google's public DNS:

```bash
dig @8.8.8.8 example.com A
```

Comparing different resolvers can help identify whether the issue is related to a specific resolver or the domain's DNS configuration.

### Trace the DNS Lookup

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

This command follows the DNS delegation path, starting from the Root DNS Servers and continuing toward the domain's authoritative Nameservers.

It helps you investigate problems with DNS delegation and Nameserver configuration.

## 5\. How to Troubleshoot DNS Step by Step

![](https://cdn.hashnode.com/uploads/covers/6ab88c552e6a138abf7988a0/3e98d38d-d04d-4d53-93af-f580533a8ac8.jpg align="center")

Let's use a practical example.

Imagine you deployed a web application and connected it to:

`app.example.com`

But the domain is not working.

Here is a simple troubleshooting workflow.

### Step 1: Check the Domain Name

First, make sure the domain and subdomain are spelled correctly.

Check that you are using the expected hostname.

For example:

- `example.com`
- `www.example.com`
- `app.example.com`

These are different hostnames and may require different DNS Records.

### Step 2: Check the DNS Records

Use `dig` or `nslookup` to inspect the records.

For example:

```bash
dig app.example.com A +short
```

Check whether the returned IP address matches the value provided by your Hosting Provider.

Also check whether the required CNAME or other record is configured correctly.

### Step 3: Check the Nameservers

Make sure the domain uses the Nameservers of the DNS Provider where you added your records.

Run:

```bash
dig example.com NS +short
```

If the domain points to different Nameservers, you may be editing DNS Records in the wrong provider's dashboard.

### Step 4: Compare Different DNS Resolvers

Query more than one Resolver:

```bash
dig @1.1.1.1 app.example.com A +short
```

```bash
dig @8.8.8.8 app.example.com A +short
```

If the results are different, caching or resolver-specific behavior may be involved.

### Step 5: Query the Authoritative Nameserver

You can query the authoritative Nameserver directly.

For example:

```bash
dig @ns1.example.net app.example.com A
```

Replace `ns1.example.net` with the actual authoritative Nameserver for your domain.

This helps you check whether the authoritative server is returning the expected record without relying on a recursive Resolver's cached answer.

### Step 6: Check the TTL and DNS Cache

If you recently changed a DNS Record, check its TTL.

Some Resolvers may still have the previous value cached.

Remember that clearing your local DNS cache only affects your device. It does not clear the cache of public or ISP DNS Resolvers.

## 6\. Clearing the Local DNS Cache

Sometimes, your device may keep old DNS information in its local cache.

You can clear it using operating system commands.

### Windows

Open Command Prompt and run:

```bash
ipconfig /flushdns
```

This clears the Windows DNS Client Resolver Cache.

### macOS

On current macOS versions, you can run:

```bash
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
```

You may need to enter your administrator password.

### Linux with systemd-resolved

If your system uses systemd-resolved, run:

```bash
sudo resolvectl flush-caches
```

The exact cache-clearing method depends on the operating system and DNS service you use.

**Important:** Clearing your local cache does not clear DNS caches on remote Resolvers.

## 7\. Useful DNS Troubleshooting Tools

Besides command-line tools, there are online services that can help developers investigate DNS problems.

### DNS Checker

DNS Checker allows you to compare DNS record results from different locations.

It can help you understand whether DNS changes are visible across different resolvers.

### Google Admin Toolbox Dig

This tool allows you to query DNS records using a web interface.

It is useful when you want to inspect DNS information without using the terminal.

### DNSViz

DNSViz analyzes DNS configuration and DNSSEC-related problems.

It can help identify issues in the DNS delegation and validation chain.

## Summary

Let's review the main tools and commands:

| Tool / Command | Purpose |
| --- | --- |
| `nslookup` | Queries DNS information |
| `dig` | Inspects DNS records and responses |
| `dig +trace` | Follows the DNS delegation path |
| `ipconfig /flushdns` | Clears the Windows local DNS cache |
| `resolvectl flush-caches` | Clears the systemd-resolved cache |
| DNS Checker | Compares DNS results from different locations |
| DNSViz | Analyzes DNS and DNSSEC configuration |

DNS troubleshooting is an important skill for developers.

Understanding DNS responses, checking DNS Records, verifying Nameservers, and using command-line tools can help you identify problems when deploying applications or connecting custom domains.

With these fundamentals, you now have a better understanding of how DNS works and how to troubleshoot common DNS issues.
