Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … curl: (6) Could not resolve host

'Could not resolve host': debugging DNS on Linux

The name couldn't be turned into an IP address.

Networking

What it means

The resolver asked its DNS server and got no answer (or NXDOMAIN). The name may be wrong, the resolver configuration broken, or the DNS server unreachable. /etc/hosts and nsswitch decide what's checked first.

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. Broken resolver configuration

Check:

cat /etc/resolv.conf
resolvectl status 2>/dev/null | head -20

Fix: Point it at working nameservers (and a search domain if short names are used).

2. The DNS server is unreachable or doesn't know the name

Check:

dig +short name; dig @1.1.1.1 +short name

Fix: If a public resolver knows it and yours doesn't, fix your resolver or its forwarding.

3. An /etc/hosts entry or nsswitch order overrides DNS

Check:

getent hosts name; grep hosts /etc/nsswitch.conf

Fix: Remove the stale hosts entry.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors