The EAI_NONAME error occurs when a system or application cannot resolve a hostname to an IP address. This is a DNS resolution failure that can happen in:
The error means that a domain name cannot be resolved.
Run:
nslookup yourdomain.com
or
dig yourdomain.com
If you get an IP address, DNS is working.
If it says "server can't find yourdomain.com: NXDOMAIN", DNS is broken.
If your server has wrong or missing DNS servers, update /etc/resolv.conf.
Open the file:
nano /etc/resolv.conf
Add Google or Cloudflare DNS:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 1.1.1.1
Save and restart networking:
systemctl restart networking
Now try running nslookup yourdomain.com again.
If you see EAI_NONAME when connecting to MySQL, the database hostname might be incorrect.
Instead of:
mysql -u user -h database.yourdomain.com -p
Try:
mysql -u user -h 127.0.0.1 -p
If the hostname must be used, add it to /etc/hosts:
nano /etc/hosts
Add:
127.0.0.1 database.yourdomain.com
Restart MySQL:
systemctl restart mysql
If Nginx or Apache logs show EAI_NONAME, check virtual host settings.
For Nginx:
nano /etc/nginx/sites-available/default
server {
listen 80;
server_name yourdomain.com;
}
For Apache:
nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName yourdomain.com
</VirtualHost>
Restart:
systemctl restart nginx
or
systemctl restart apache2
If DNS was recently updated, clear the cache:
systemd-resolve --flush-caches
For macOS:
sudo killall -HUP mDNSResponder
Check if external requests fail:
curl -I yourdomain.com
or
wget yourdomain.com
If it fails:
ufw status)| Issue | Fix |
|---|---|
| Domain not resolving (EAI_NONAME) | Set correct DNS in /etc/resolv.conf |
| MySQL hostname not found | Use 127.0.0.1 or update /etc/hosts |
| Nginx/Apache virtual host error | Correct server_name or ServerName |
| Network issues | Flush DNS with systemd-resolve --flush-caches |
| cURL/Wget failing | Try using IP instead of hostname |
Now EAI_NONAME should be resolved!