LinuxCritical
Fix: DNS Resolution Failure
curl or wget fails with 'Could not resolve host'
!Symptoms
- curl or wget fails with 'Could not resolve host'
- ping shows 'Name or service not known'
- Applications fail to connect to external services
- Browser shows DNS_PROBE_FINISHED_NXDOMAIN
- Kubernetes pods cannot resolve service names
?Root Causes
- /etc/resolv.conf has wrong or unreachable nameservers
- DNS server is down or overloaded
- Network configuration changed (DHCP lease renewal, VPN toggle)
- In Kubernetes: CoreDNS pods are down or misconfigured
- Firewall blocking UDP port 53 outbound
- systemd-resolved service is crashed
#Diagnosis Steps
- 1Test DNS resolution: `nslookup google.com` or `dig google.com`
- 2Check current DNS config: `cat /etc/resolv.conf`
- 3Test with a known public DNS: `dig @8.8.8.8 google.com`
- 4For Kubernetes: `kubectl get pods -n kube-system -l k8s-app=kube-dns`
- 5Check if systemd-resolved is running: `systemctl status systemd-resolved`
- 6Test connectivity to DNS port: `nc -zvu <dns-server> 53`
>Fix
- 1Temporarily use public DNS: add `nameserver 8.8.8.8` to /etc/resolv.conf
- 2Restart systemd-resolved: `systemctl restart systemd-resolved`
- 3In Kubernetes, restart CoreDNS: `kubectl rollout restart deployment/coredns -n kube-system`
- 4Fix firewall rules to allow outbound UDP/TCP 53
- 5Flush DNS cache: `systemd-resolve --flush-caches` or `resolvectl flush-caches`
*Prevention
- Configure multiple DNS servers in resolv.conf for redundancy
- Monitor DNS resolution latency and failure rates
- In Kubernetes, ensure CoreDNS has adequate resources and replicas
- Use ndots and search domain settings appropriate for your environment
- Set up DNS health checks in your monitoring stack
Related Error Messages
Could not resolve hostName or service not knownDNS_PROBE_FINISHED_NXDOMAINTemporary failure in name resolutionSERVFAILNXDOMAIN