Question
What does the following error mean when I find it in the MySQL / MariaDB error log?
Host name example.com could not be resolved: Name or service not known
Answer
MySQL has the ability to perform hostname based authentication. This means that you can specify that a username can only connect if that username is connecting from a specific hostname.
MySQL does two DNS lookups to check the hostname of an IP address.
First, MySQL a DNS query to find the PTR record of the IP address of each client connection. This will give the hostname that MySQL checks against.
One way to simulate this DNS query is to use the following dig command which returns dns.google as the PTR record:
dig +short -x 8.8.8.8
dns.google.
But this first query is not enough because the PTR record can be set to any host.
In order to ensure that the PTR record is valid, a second query is performed to check the A record of the hostname returned by the PTR record to ensure that it points back to the original IP address:
This can be simulated with the following dig command which returns 8.8.8.8 and 4.4.4.4 as the A records:
dig +short dns.google.
8.8.4.4
8.8.8.8
If there is no A record returned for the hostname provided in the PTR record the following error is logged by MySQL:
Host name example.com could not be resolved: Name or service not known
This error message is of no concern for you unless you are unable to connect to MySQL. Any server that has a port open to the public will face a constant barrage of random connections which will produce many errors like this which is very typical.
This error message is only of concern to you if you have configured allowed access for a specific hostname and your IP address's PTR record and corresponding A record are not set up properly.
For a bit of background, the following article explains the process of allowing access for a specific hostname: