Fix "EAI_NONAME" Error – Complete DNS Resolution Guide
The "EAI_NONAME - Neither nodename nor servname provided, or not known" error indicates that DNS resolution is failing on your Linux system, preventing applications from converting hostnames (like yourdomain.com) to IP addresses. This comprehensive guide will help you fix DNS configuration in /etc/resolv.conf and related system files.
Common Symptoms: This error often appears when using tools like curl, wget, ssh, FTP clients, Node.js applications, or during package updates (apt-get update). The root cause is typically incorrect or missing DNS server configuration.
Understanding the Error
The EAI_NONAME error means the system's Domain Name System (DNS) resolver cannot find the IP address associated with a given hostname. This can happen because:
/etc/resolv.conf is empty, corrupted, or contains invalid DNS servers
- NetworkManager or systemd-resolved is misconfigured
- DNS servers are unreachable or blocking requests
- Local DNS cache contains stale or incorrect records
- Firewall rules are blocking DNS traffic (port 53)
Check Your Current DNS Configuration
First, examine your current DNS settings to identify the problem.
# Check the main DNS configuration file
cat /etc/resolv.conf
# Check active DNS servers being used
systemd-resolve --status | grep "DNS Servers"
# Alternative method using nmcli (if using NetworkManager)
nmcli device show | grep DNS
Expected Output Example (working configuration):
nameserver 8.8.8.8
nameserver 8.8.4.4
# Optional: search domain localdomain
If the file is empty, contains only comments, or lists unreachable DNS servers, you've found the issue.
Update /etc/resolv.conf with Correct DNS Servers
If /etc/resolv.conf is incorrect, update it with reliable public DNS servers.
Method 1: Manual Edit (Temporary Fix)
# Backup the original file (optional)
sudo cp /etc/resolv.conf /etc/resolv.conf.backup
# Edit the file
sudo nano /etc/resolv.conf
Replace the contents with reliable DNS servers. Here are popular options:
# Google Public DNS
nameserver 8.8.8.8
nameserver 8.8.4.4
# Cloudflare DNS
nameserver 1.1.1.1
nameserver 1.0.0.1
# Combined approach (primary and backup)
nameserver 8.8.8.8
nameserver 1.1.1.1
nameserver 8.8.4.4
Save the file (Ctrl+X, then Y, then Enter).
DNS Server Recommendations:
- Google DNS (8.8.8.8, 8.8.4.4): Fast and reliable, good general-purpose choice
- Cloudflare DNS (1.1.1.1, 1.0.0.1): Privacy-focused with good performance
- Your ISP's DNS: Sometimes faster for local content (check your ISP documentation)
- OpenDNS (208.67.222.222, 208.67.220.220): Additional security features
Make /etc/resolv.conf Permanent
Many Linux distributions automatically overwrite /etc/resolv.conf. Use these methods to make your changes permanent.
Method 1: Prevent File Overwriting (chattr)
# Make the file immutable (cannot be changed)
sudo chattr +i /etc/resolv.conf
# To edit the file later, first remove the immutable flag
sudo chattr -i /etc/resolv.conf
Note: The chattr +i method is simple but can break systems that rely on dynamic DNS updates (like DHCP clients or VPN connections). Use with caution on laptops or systems that change networks frequently.
Method 2: Configure systemd-resolved (Ubuntu/Debian/Fedora)
Most modern distributions use systemd-resolved to manage DNS.
# Edit the systemd-resolved configuration
sudo nano /etc/systemd/resolved.conf
Uncomment and modify these lines:
[Resolve]
DNS=8.8.8.8 1.1.1.1
FallbackDNS=8.8.4.4 1.0.0.1
Domains=~.
DNSStubListener=yes
Apply the changes:
# Restart the service
sudo systemctl restart systemd-resolved
# Ensure /etc/resolv.conf points to systemd's stub resolver (should be a symlink)
ls -la /etc/resolv.conf
# Should show: /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
Method 3: Configure NetworkManager (if used)
# Edit NetworkManager connection (replace 'eth0' with your interface)
sudo nmcli connection modify eth0 ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli connection modify eth0 ipv4.ignore-auto-dns yes
# Apply changes
sudo nmcli connection down eth0 && sudo nmcli connection up eth0
Flush DNS Cache
After updating DNS settings, clear any stale DNS cache.
# For systemd-resolved (most modern systems)
sudo systemd-resolve --flush-caches
# or
sudo resolvectl flush-caches
# For dnsmasq (if installed)
sudo systemctl restart dnsmasq
# For nscd (Name Service Cache Daemon)
sudo systemctl restart nscd
# Check if caching was cleared
sudo systemd-resolve --statistics
Test DNS Resolution
Verify that DNS is now working correctly.
# Test with nslookup
nslookup google.com
nslookup yourdomain.com
# Test with dig (more detailed)
dig google.com +short
dig yourdomain.com ANY
# Test direct resolution
getent hosts google.com
# Test connectivity to DNS servers
ping -c 3 8.8.8.8
nc -zv 8.8.8.8 53
Expected Success: These commands should return IP addresses, not errors or timeouts.
Restart Networking
If DNS issues persist, restart your network services.
# For systemd-networkd
sudo systemctl restart systemd-networkd
# For NetworkManager
sudo systemctl restart NetworkManager
# or
sudo nmcli networking off && sudo nmcli networking on
# For older systems with networking service
sudo systemctl restart networking
# Complete network restart (if all else fails)
sudo reboot
Advanced Troubleshooting
Check for Firewall Issues
Ensure your firewall isn't blocking DNS traffic (port 53):
# Check iptables rules
sudo iptables -L -n | grep :53
# Check firewalld
sudo firewall-cmd --list-all | grep services
# Temporarily disable firewall for testing
sudo systemctl stop firewalld # or ufw/iptables
# Test DNS, then re-enable with proper rules
Check /etc/hosts File
Ensure there are no incorrect entries in the hosts file that might override DNS:
# Check /etc/hosts for problematic entries
cat /etc/hosts
# The file should have minimal entries, typically:
# 127.0.0.1 localhost localhost.localdomain
# ::1 localhost localhost.localdomain
Check DNS Server Connectivity
Test if you can reach your DNS servers:
# Test DNS server response
dig @8.8.8.8 google.com
# Check DNS server reachability on port 53
timeout 2 nc -z 8.8.8.8 53 && echo "Port 53 open" || echo "Port 53 blocked"
# Test with different DNS servers to isolate the issue
for dns in 8.8.8.8 1.1.1.1 208.67.222.222; do
echo "Testing $dns:" && dig @$dns google.com +short +time=2
done
Debug DNS Resolution Process
Use tools to trace the DNS resolution process:
# Trace DNS resolution with systemd
resolvectl query google.com
# Check DNS configuration sources
resolvectl status
# Detailed debug information
systemd-resolve --status --verbose
Summary of Fixes for "EAI_NONAME"
| Issue |
Fix |
Command |
Empty/incorrect /etc/resolv.conf |
Manually add DNS servers |
sudo nano /etc/resolv.conf add nameserver 8.8.8.8 |
| File gets reset automatically |
Configure systemd-resolved or use chattr |
sudo nano /etc/systemd/resolved.conf or sudo chattr +i /etc/resolv.conf |
| Stale DNS cache |
Flush DNS cache |
sudo systemd-resolve --flush-caches |
| Network configuration issues |
Restart networking services |
sudo systemctl restart systemd-networkd |
| Firewall blocking DNS |
Allow port 53 traffic |
sudo ufw allow out 53/tcp and sudo ufw allow out 53/udp |
| Application-specific issue |
Check application DNS settings |
Configure DNS in app settings or use export NODE_OPTIONS="--dns-result-order=ipv4first" for Node.js |
Final Verification: After applying fixes, run a comprehensive test: ping google.com should work, and dig yourdomain.com should return correct IP addresses without errors. If problems persist, check your network hardware (router/modem) and ISP connectivity.
High-Availability Cloud VDS
- Uptime Р 99.95%
- Network bandwidth Р 1 Gb/s
- Technical support 24/7/365
learn more...