DNS Resolution Errors: Diagnosis & Fix Guide

DNS Resolution Errors: Diagnosis & Fix Guide

DNS resolution errors occur when your system cannot translate a domain name into an IP address. Without successful DNS resolution, no HTTP connection can be established. This guide covers how to diagnose and fix DNS errors in cURL, Python, browsers, and proxy setups.

What Is DNS Resolution?

DNS (Domain Name System) translates human-readable domain names like example.com into IP addresses like 93.184.216.34. When this process fails, you see errors like:

  • curl: (6) Could not resolve host
  • socket.gaierror: Name or service not known
  • DNS_PROBE_FINISHED_NXDOMAIN (Chrome)
  • Server Not Found (Firefox)

Common DNS Errors

ErrorToolMeaning
Could not resolve hostcURLDNS lookup returned no results
Could not resolve proxycURLProxy hostname could not be resolved
Name or service not knownPythonDNS lookup failed
DNS_PROBE_FINISHED_NXDOMAINChromeDomain does not exist
DNS_PROBE_FINISHED_NO_INTERNETChromeNo internet connection
SERVFAILdig/nslookupDNS server failed to process query
NXDOMAINdig/nslookupDomain name does not exist

Diagnosing DNS Issues

Check with Command-Line Tools

# Basic DNS lookup

nslookup example.com

dig example.com

Check specific DNS server

dig @8.8.8.8 example.com

dig @1.1.1.1 example.com

nslookup example.com 8.8.8.8

Check all record types

dig example.com ANY

Trace the DNS resolution path

dig +trace example.com

Check reverse DNS

dig -x 93.184.216.34

Check DNS response time

dig example.com | grep "Query time"

Check with cURL

# Verbose output shows DNS resolution

curl -v https://example.com 2>&1 | grep -E "Trying|resolve"

Measure DNS lookup time

curl -w "DNS: %{time_namelookup}s\n" -o /dev/null -s https://example.com

Use specific DNS server (cURL 7.62+)

curl --dns-servers 8.8.8.8 https://example.com

Bypass DNS with --resolve

curl --resolve example.com:443:93.184.216.34 https://example.com

Check with Python

import socket

try:

ip = socket.gethostbyname("example.com")

print(f"Resolved to: {ip}")

except socket.gaierror as e:

print(f"DNS error: {e}")

Get all IPs for a domain

try:

results = socket.getaddrinfo("example.com", 443)

for result in results:

print(f" {result[4][0]}")

except socket.gaierror as e:

print(f"DNS error: {e}")

Fix 1: Flush DNS Cache

Stale DNS cache entries can cause resolution failures.

# macOS

sudo dscacheutil -flushcache

sudo killall -HUP mDNSResponder

Linux (systemd-resolved)

sudo systemd-resolve --flush-caches

Windows

ipconfig /flushdns

Fix 2: Change DNS Servers

Your ISP’s DNS server may be slow, unreliable, or censoring domains.

# Test with Google DNS

dig @8.8.8.8 example.com

Test with Cloudflare DNS

dig @1.1.1.1 example.com

Test with OpenDNS

dig @208.67.222.222 example.com

Permanently change DNS (Linux):

# Edit resolv.conf

sudo nano /etc/resolv.conf

Add:

nameserver 8.8.8.8

nameserver 1.1.1.1

Or use systemd-resolved

sudo nano /etc/systemd/resolved.conf

[Resolve]

DNS=8.8.8.8 1.1.1.1

sudo systemctl restart systemd-resolved

Popular DNS Servers:

ProviderPrimarySecondary
Google8.8.8.88.8.4.4
Cloudflare1.1.1.11.0.0.1
OpenDNS208.67.222.222208.67.220.220
Quad99.9.9.9149.112.112.112

Fix 3: Check /etc/hosts File

Local hosts file entries override DNS resolution.

# Check hosts file

cat /etc/hosts

Add a manual entry if DNS is failing

echo "93.184.216.34 example.com" | sudo tee -a /etc/hosts

Fix 4: DNS Resolution with Proxies

When using proxies, DNS resolution can happen on either the client or the proxy server side.

# SOCKS5 proxy with remote DNS resolution (proxy resolves DNS)

curl --socks5-hostname proxy.example.com:1080 https://example.com

SOCKS5 proxy with local DNS resolution (client resolves DNS)

curl --socks5 proxy.example.com:1080 https://example.com

HTTP proxy (proxy always resolves DNS)

curl -x http://proxy.example.com:8080 https://example.com

import requests

HTTP proxy - DNS resolved by proxy server

proxies = {"https": "http://user:pass@proxy.example.com:8080"}

response = requests.get("https://example.com", proxies=proxies)

SOCKS5 with remote DNS

proxies = {"https": "socks5h://user:pass@proxy.example.com:1080"} # 'h' = remote DNS

response = requests.get("https://example.com", proxies=proxies)

Using a proxy with remote DNS resolution can bypass local DNS issues or censorship. Residential proxies resolve DNS from the proxy’s location, which is useful for accessing geo-restricted content.

Fix 5: DNS Over HTTPS (DoH)

Encrypted DNS prevents ISP interference and improves privacy.

# Test DNS over HTTPS with cURL

curl -s "https://dns.google/resolve?name=example.com&type=A" | python3 -m json.tool

Use DoH with cURL (7.62+)

curl --doh-url https://dns.google/dns-query https://example.com

curl --doh-url https://cloudflare-dns.com/dns-query https://example.com

Fix 6: Check for Domain Issues

The domain itself may be the problem.

# Check if domain is registered

whois example.com

Check nameservers

dig NS example.com

Check domain propagation (after DNS changes)

dig @ns1.example.com example.com

dig @8.8.8.8 example.com

DNS Error Handling in Code

import requests

import socket

def request_with_dns_fallback(url, fallback_dns=None):

try:

response = requests.get(url, timeout=10)

return response

except requests.exceptions.ConnectionError as e:

if "Name or service not known" in str(e) or "nodename nor servname" in str(e):

print(f"DNS resolution failed for {url}")

if fallback_dns:

# Try resolving with alternative DNS

import urllib.parse

parsed = urllib.parse.urlparse(url)

hostname = parsed.hostname

try:

# Manual DNS resolution

ip = socket.gethostbyname(hostname)

print(f"Resolved {hostname} to {ip}")

except socket.gaierror:

print("Fallback DNS also failed")

raise

raise

Usage

response = request_with_dns_fallback("https://example.com")



FAQ

What does NXDOMAIN mean?

NXDOMAIN means the domain name does not exist in DNS. This could mean the domain was never registered, has expired, or has been removed.

Why does DNS resolution work in my browser but not in cURL?

Browsers may use DNS over HTTPS, cached results, or different DNS settings than your terminal. Try flushing your DNS cache and check that your system DNS settings are correct.

Can a VPN or proxy fix DNS errors?

Yes. If the DNS error is caused by your ISP blocking or failing to resolve a domain, routing through a VPN or proxy with remote DNS resolution bypasses the issue entirely.

How long does DNS propagation take?

DNS changes can take up to 48 hours to propagate globally, though most updates propagate within 1-4 hours. During propagation, some users may resolve the old IP while others see the new one.

Scroll to Top