🔧 Error Fixes
· 1 min read

DNS Resolution Failed — How to Fix It


Error: getaddrinfo ENOTFOUND api.example.com
socket.gaierror: [Errno -2] Name or service not known
DNS_PROBE_FINISHED_NXDOMAIN

Your system can’t translate the hostname into an IP address. The DNS lookup failed.

Fix 1: Typo in the Hostname

# ❌ Common typos
curl https://api.exmaple.com    # Misspelled
curl https://api.example.comm   # Wrong TLD

# ✅ Verify the hostname
nslookup api.example.com
dig api.example.com

Fix 2: DNS Server Is Down

# Check which DNS server you're using
cat /etc/resolv.conf

# Try a different DNS server
nslookup api.example.com 8.8.8.8        # Google DNS
nslookup api.example.com 1.1.1.1        # Cloudflare DNS

# Temporarily switch DNS
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

Fix 3: Docker Container Can’t Resolve DNS

# docker-compose.yml — add DNS servers
services:
  app:
    dns:
      - 8.8.8.8
      - 8.8.4.4
# Or pass DNS to docker run
docker run --dns 8.8.8.8 myapp

Fix 4: /etc/hosts Override

# Check if the hostname is overridden locally
cat /etc/hosts | grep example.com

# Add a manual entry if DNS is broken
echo "93.184.216.34 api.example.com" | sudo tee -a /etc/hosts

Fix 5: VPN or Proxy Blocking DNS

# Disconnect VPN and try again
# If it works without VPN, your VPN's DNS is the issue

# Some VPNs need split tunneling for specific domains
# Check your VPN client settings

Fix 6: Flush DNS Cache

# macOS
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

# Linux (systemd-resolved)
sudo systemd-resolve --flush-caches

# Windows
ipconfig /flushdns

Debugging

# 1. Can you resolve the hostname?
nslookup api.example.com

# 2. Can you reach the IP directly?
curl -v http://93.184.216.34

# 3. Is it a local DNS issue?
dig api.example.com @8.8.8.8

# 4. Is the domain registered?
whois example.com