Name or service not known
The Name or service not known error means that the system failed to resolve a hostname into an IP address because the name does not exist or cannot be resolved by the configured DNS resolver. This is a global ROOT-level DNS error that occurs across Linux and Unix-based systems, containers, Java and Spring Boot applications, databases, and network services when hostname resolution fails.
When does this error occur?
- Accessing a hostname that does not exist in DNS
- Using an incorrect or misspelled domain or service name
- DNS resolver configuration is missing or invalid
- Containers or servers running without proper DNS settings
- Applications starting before DNS services are available
Root cause of Name or service not known
At the OS resolver level, Name or service not known occurs when the DNS lookup returns a permanent failure, indicating that the requested hostname cannot be resolved. This typically means the name is invalid, does not exist in DNS records, or the resolver configuration cannot locate an authoritative response.
How to fix the error (step-by-step)
Linux / macOS
Verify basic network connectivity.
ping 8.8.8.8
Test DNS resolution for the hostname.
nslookup example.com
dig example.com
Check DNS resolver configuration.
cat /etc/resolv.conf
Ensure valid DNS servers are configured.
nameserver 8.8.8.8
nameserver 1.1.1.1
Windows
Test hostname resolution.
nslookup example.com
Flush the DNS cache.
ipconfig /flushdns
Verify DNS settings on the network adapter.
Java / Spring Boot
Confirm that the hostname used by the application is valid and resolvable.
InetAddress.getByName("example.com");
Avoid hardcoding hostnames that do not exist in DNS or local hosts files.
Docker / containers
Check DNS configuration inside the container.
docker exec -it <container_id> cat /etc/resolv.conf
Test hostname resolution from the container.
docker exec -it <container_id> ping example.com
Specify DNS servers explicitly if needed.
docker run --dns 8.8.8.8 --dns 1.1.1.1 <image>
Database / network services
Ensure database hostnames are correct and resolvable during service startup.
Verify the fix
Retry the original command or application request. The issue is resolved when the hostname consistently resolves to an IP address and services can connect without DNS-related failures.
Common mistakes to avoid
- Assuming the error is temporary when the hostname is invalid
- Editing resolv.conf without understanding system DNS management
- Using internal hostnames outside their network scope
- Ignoring container-specific DNS behavior
- Not validating DNS records after changes
Quick tip
Always verify that a hostname exists in DNS or local host mappings before deploying it in production systems.
FAQ
Q: How is this different from Temporary failure in name resolution?
A: This error indicates a permanent DNS resolution failure, while temporary failure usually points to transient network or DNS availability issues.
Q: Can this error occur even if the internet is working?
A: Yes. Internet connectivity can be available, but DNS resolution can still fail for specific hostnames.
Conclusion
The Name or service not known error indicates a DNS resolution failure caused by invalid or unresolvable hostnames. Proper DNS configuration and hostname validation prevent this issue. Explore related DNS ROOT errors on ErrorFixHub for further guidance.
Comments
Post a Comment