Linux DNS Not Resolving? How to Troubleshoot DNS Issues Layer by Layer

Your Linux server has internet access, but applications cannot resolve domain names. Learn how to troubleshoot DNS layer by layer, investigate systemd-resolved, inspect resolver configuration, diagnose Docker DNS issues, and fix the actual cause without blindly changing nameservers.

Share
Linux DNS troubleshooting illustration featuring Tux, server racks, and a magnifying glass highlighting DNS resolution errors.

Your Linux server can reach the internet. SSH works, applications are running, and you can even ping public IP addresses. But the moment an application tries to connect to a service using a domain name, everything breaks.

You run:

curl https://example.com

And receive:

curl: (6) Could not resolve host: example.com

You check the network interface. It is up. The default gateway is reachable. There is no obvious network outage.

So, what is actually failing?

DNS is often the first suspect, but changing nameservers without understanding the problem can make things worse. The failure could be in the application's resolution path, /etc/resolv.conf, systemd-resolved, an upstream DNS server, a firewall rule, or even Docker's internal DNS service.

The better approach is to identify exactly where name resolution breaks.

In this guide, we'll troubleshoot Linux DNS issues layer by layer, starting with the application and moving toward the resolver and network infrastructure.

Linux DNS resolution flow diagram showing an application, NSS configuration, resolver configuration, systemd-resolved, and an upstream DNS server.

1. Confirm that the problem is actually DNS

Before modifying any configuration, reproduce the failure and establish what is working.

Start by testing hostname resolution:

getent hosts example.com

If the command returns an IP address, the system's configured name-resolution path successfully resolved the hostname.

If it returns nothing, investigate further.

Now test basic IP connectivity:

ping -c 3 1.1.1.1

If this succeeds while hostname resolution fails, you have an important clue: basic IP connectivity is available, but name resolution may not be working.

Try the application again:

curl -v https://example.com

Pay attention to the error:

  • Could not resolve host indicates a hostname resolution failure.
  • Connection timed out may indicate a connectivity or service response problem.
  • Connection refused generally means the destination was reachable but rejected the connection.
  • TLS or certificate errors occur later in the connection process and are not necessarily DNS problems.

A successful ping to an IP address does not prove that all network services are working. It only demonstrates that ICMP traffic to that destination received a response.

The objective is to distinguish a DNS failure from a general network connectivity problem before changing anything.

2. Inspect the Linux resolver configuration

Linux needs to know which DNS servers should handle hostname queries.

Start by examining:

cat /etc/resolv.conf

A typical configuration might look like:

nameserver 127.0.0.53
options edns0 trust-ad
search example.local

Or:

nameserver 1.1.1.1
nameserver 8.8.8.8

The nameserver directive identifies the DNS server used by traditional resolver clients.

In the first example, 127.0.0.53 is commonly used by systemd-resolved as a local DNS stub listener. It is not an external DNS server. It receives local queries and forwards them to configured upstream resolvers.

If the local resolver is unavailable or incorrectly configured, applications may fail even when external DNS servers are reachable.

Next, check whether /etc/resolv.conf is managed by another service:

ls -l /etc/resolv.conf

You might find:

/etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf

This indicates that systemd-resolved manages the resolver configuration.

Other systems may use NetworkManager, DHCP clients, or different resolver management mechanisms.

Also inspect the Name Service Switch configuration:

grep '^hosts:' /etc/nsswitch.conf

A typical entry looks like:

hosts: files dns

This controls the order in which Linux looks up hostnames. files generally refers to /etc/hosts, while dns uses DNS.

Other modules, such as resolve, may also appear.

This matters because applications using the standard system resolver do not necessarily follow the same path as a direct DNS query.

For further reference, see the Linux manual pages for resolv.conf and nsswitch.conf.

3. Investigate systemd-resolved

Many modern Linux distributions use systemd-resolved to manage DNS resolution.

If /etc/resolv.conf points to 127.0.0.53, this is one of the first services to investigate.

Check its status:

systemctl status systemd-resolved

If the service is inactive or failed, inspect its logs:

journalctl -u systemd-resolved -n 100 --no-pager

Next, inspect the resolver configuration:

resolvectl status

Pay attention to:

  • DNS servers assigned to each network interface.
  • The currently selected DNS server.
  • Search and routing domains.
  • Whether the interface is configured to use DNS.

A server might have a valid global DNS configuration but an interface-specific configuration that takes precedence for certain queries.

Test resolution directly through systemd-resolved:

resolvectl query example.com

You can also check whether the local stub listener is active:

ss -luntp | grep ':53'

If applications are configured to query 127.0.0.53 but nothing is listening there, the local resolution path is broken.

For more details, consult the official systemd-resolved documentation and resolvectl manual.

4. Test DNS independently using dig

Now move beyond the system resolver.

The dig utility allows you to send DNS queries directly to a specified DNS server.

Install it if necessary.

On Debian or Ubuntu:

sudo apt install dnsutils

On RHEL-family distributions:

sudo dnf install bind-utils

Start with a normal DNS query:

dig example.com

Look for the answer section:

;; ANSWER SECTION:
example.com.    300    IN    A    93.184.216.34

The returned address and TTL can vary.

Now query a specific DNS server:

dig @1.1.1.1 example.com

Try another resolver if your network permits it:

dig @8.8.8.8 example.com

Linux DNS troubleshooting illustration showing getent and dig commands returning DNS results alongside a failed curl hostname resolution.

Compare the results.

Test Result Possible interpretation
getent hosts example.com Fails System name-resolution path may be broken
dig example.com Fails Configured resolver may be unavailable
dig @1.1.1.1 example.com Works Investigate local resolver configuration
All queries fail Fails Investigate connectivity, firewall, and upstream DNS

These results are diagnostic clues, not definitive conclusions. A direct query may succeed while an application still fails because the application uses a different resolution path.

Understand common DNS response codes

When inspecting dig output, pay attention to the response status.

Response Meaning
NOERROR Query completed successfully; the requested record may or may not exist
NXDOMAIN The queried domain name does not exist according to the responding server
SERVFAIL The DNS server could not complete the query
REFUSED The server refused the query
Timeout No usable response arrived within the configured time

For example, NXDOMAIN is not necessarily a network problem. It may indicate an incorrect hostname or a missing DNS record.

Similarly, SERVFAIL may point toward an upstream resolution issue, DNSSEC validation failure, or another resolver-side problem.

For additional examples, see the BIND 9 DNS diagnostic documentation.

5. Investigate DNS timeouts and network restrictions

Sometimes DNS resolution works intermittently.

A hostname resolves successfully on one attempt but fails on the next.

Possible causes include:

  • Unreachable or overloaded upstream resolvers.
  • Firewall rules blocking DNS traffic.
  • Network instability.
  • Incorrect routing.
  • Problems with private DNS infrastructure.

DNS commonly uses UDP port 53, but TCP port 53 is also important. Larger responses and certain DNS operations require TCP.

Test a direct UDP query:

dig @1.1.1.1 example.com +time=2 +tries=1

Then test TCP:

dig @1.1.1.1 example.com +tcp +time=2 +tries=1

If UDP works but TCP fails, investigate firewall rules and network policies affecting TCP port 53.

If both fail, your network may restrict outbound DNS traffic to approved resolvers.

Inspect firewall configuration where appropriate:

sudo nft list ruleset

On systems using UFW:

sudo ufw status verbose

Also check routing:

ip route

If the server uses private or corporate DNS infrastructure, confirm that the configured resolver is reachable through the expected interface and route.

Do not open outbound DNS traffic to every public resolver as a first response. Some environments intentionally restrict DNS queries to internal resolvers for security, filtering, and logging.

6. Why DNS works on the host but fails inside Docker

Container networking introduces another layer of DNS configuration.

You might find that this works on the host:

getent hosts example.com

But the same lookup fails inside a container.

Start by inspecting the container's resolver configuration:

docker exec <container_name> cat /etc/resolv.conf

On Docker user-defined bridge networks, you may see:

nameserver 127.0.0.11
options ndots:0

The address 127.0.0.11 is Docker's embedded DNS resolver for containers on supported user-defined networks.

It handles container name resolution and forwards external DNS queries to the DNS servers configured for the host.

Docker DNS troubleshooting diagram showing a Linux host, Docker container using embedded DNS at 127.0.0.11, and an upstream DNS server.

Test from inside the container:

docker exec <container_name> getent hosts example.com

If getent is unavailable, use an available diagnostic utility or a temporary container:

docker run --rm \
  --network <network_name> \
  busybox nslookup example.com

Also inspect the container's network configuration:

docker inspect <container_name>

Pay attention to its network mode and attached networks.

Docker can also use explicitly configured DNS servers. Inspect the daemon configuration:

cat /etc/docker/daemon.json

An example configuration:

{
  "dns": ["192.168.1.1", "1.1.1.1"]
}

Use DNS servers appropriate for your environment, especially if containers need to resolve internal hostnames.

Docker DNS behavior differs between user-defined bridge networks, the default bridge network, and host networking. For the exact behavior, consult the official Docker networking documentation.

If DNS works on the host but fails only inside one container, investigate that container's network rather than changing the entire host resolver configuration.

7. Fix the actual problem, not just the symptoms

Once you identify the failing layer, correct the configuration at its source.

For example:

  • If systemd-resolved is not running, investigate why the service failed before restarting it.
  • If NetworkManager provides an incorrect DNS server, correct the connection profile.
  • If DHCP assigns an unexpected resolver, investigate the DHCP configuration.
  • If a firewall blocks DNS traffic, correct the relevant network policy.
  • If Docker containers use an incorrect resolver, investigate Docker's DNS configuration.

For systems managed by systemd-resolved, you can make a runtime DNS change:

sudo resolvectl dns eth0 1.1.1.1

Replace eth0 with the actual interface name.

This change is not necessarily persistent. A network management service may overwrite it later.

For a permanent correction, update the configuration through the service managing the interface, such as NetworkManager or systemd-networkd.

After correcting the configuration, test again:

getent hosts example.com
dig example.com
curl -I https://example.com

Testing through multiple tools helps confirm that both the system resolver and the application can now resolve the hostname.

Avoid changing several DNS settings simultaneously. If the problem disappears, you should know which change actually fixed it.

8. A practical Linux DNS troubleshooting checklist

When DNS fails on a production Linux server, follow a consistent diagnostic sequence instead of randomly changing nameservers.

Investigation Command
Test system hostname resolution getent hosts example.com
Test basic IP connectivity ping -c 3 1.1.1.1
Inspect resolver configuration cat /etc/resolv.conf
Inspect NSS configuration grep '^hosts:' /etc/nsswitch.conf
Check systemd-resolved systemctl status systemd-resolved
Inspect DNS configuration resolvectl status
Test systemd resolution resolvectl query example.com
Query configured DNS dig example.com
Query a specific DNS server dig @1.1.1.1 example.com
Test DNS over TCP dig @1.1.1.1 example.com +tcp
Inspect network routes ip route
Inspect firewall rules sudo nft list ruleset
Inspect Docker resolver docker exec <container_name> cat /etc/resolv.conf

A useful troubleshooting sequence is:

  1. Reproduce the failure from the affected application.
  2. Check whether the hostname resolves through getent.
  3. Inspect /etc/resolv.conf and /etc/nsswitch.conf.
  4. Investigate systemd-resolved if the system uses it.
  5. Compare normal DNS queries with direct queries to a specific resolver.
  6. Check routing, firewall rules, and DNS connectivity.
  7. If containers are affected, investigate their network and resolver configuration.
  8. Make one targeted correction and test again.

Document your findings, especially when the problem involves production infrastructure. Intermittent DNS failures are easier to diagnose when you have timestamps, resolver information, and logs from the affected system.

Final thoughts: Troubleshoot DNS by following the resolution path

DNS problems can be frustrating because the server may appear perfectly healthy while applications cannot reach the services they depend on.

The mistake is assuming that every DNS failure requires a different nameserver.

Sometimes the upstream resolver is fine, but systemd-resolved is unavailable. Sometimes /etc/resolv.conf points to an incorrect address. Other times, the host resolves domains correctly while Docker containers cannot.

Each situation requires a different fix.

The most reliable approach is to follow the resolution path from the application toward the DNS infrastructure, testing each layer independently.

Tools such as getent, dig, resolvectl, journalctl, and docker inspect provide enough visibility to isolate many common Linux DNS failures without making unnecessary configuration changes.

The next time a Linux server cannot resolve a hostname, don't start by changing nameservers.

Find the layer that is failing, understand why it is failing, and fix that layer.