Skip to content

Setting `skip_name_resolve` on a cPanel MySQL host — connection speed vs grant flexibility

Without skip_name_resolve, MySQL does a reverse-DNS lookup on every connection. Enabling it makes connects faster and stricter — every host-based grant must use an IP, not a name.

A cPanel admin notices new MySQL connections take 2+ seconds during peak traffic. MySQL itself is healthy; queries finish in milliseconds. The delay is in the connection setup, before any query runs. The culprit is MySQL’s default behavior of doing a reverse-DNS lookup on every incoming connection to match grants like 'user'@'somehost.example.com'. If DNS is slow or the configured resolver has stale entries, this can stall every connection. skip_name_resolve turns it off — at the cost of breaking any grant that uses a hostname instead of an IP.

What’s happening

When MySQL receives a connection from 203.0.113.42, it normally does a reverse-DNS lookup to get host42.example.com, then matches against mysql.user looking for entries like 'user'@'host42.example.com'. If mysql.user only has IP-based entries ('user'@'203.0.113.42' or 'user'@'%'), the reverse-DNS lookup is wasted work — MySQL still ends up matching by IP. On a busy cPanel host with hundreds of new connections per second, that wasted DNS work adds latency to every connection.

skip_name_resolve = ON tells MySQL to never do reverse-DNS. Hostnames in grants are then ignored — 'user'@'host42.example.com' will never match anything. Only localhost, 127.0.0.1, and explicit IP-based grants work.

cPanel’s defaults: the platform creates grants with localhost, which is a special-case shortcut (Unix socket, no DNS needed). Remote MySQL grants are created with IPs ('user'@'203.0.113.42'), not hostnames. So skip_name_resolve is usually safe on cPanel — the grants the platform creates don’t depend on DNS.

How to verify

mysql -e "SHOW VARIABLES LIKE 'skip_name_resolve'"
mysql -e "SHOW STATUS LIKE 'Connections'"
mysql -e "SELECT User, Host FROM mysql.user WHERE Host NOT IN ('localhost','127.0.0.1','::1','%') AND Host NOT REGEXP '^[0-9.]+$'"
mysql -e "SHOW STATUS LIKE 'Aborted_connects'"
time mysql -e "SELECT 1"

The third query lists any host-based grants that use a non-IP — these will break if you enable skip_name_resolve. Empty result means you’re safe.

The fix

  1. Audit hostname-based grants — if the query above returns rows, decide for each:
    • Convert to IP: if the hostname resolves to a stable IP, replace the grant:
      CREATE USER 'app'@'203.0.113.42' IDENTIFIED BY 'pwd';
      GRANT ... ON db.* TO 'app'@'203.0.113.42';
      DROP USER 'app'@'host42.example.com';
    • Use wildcard: if the source IP varies, 'app'@'203.0.113.%' for a /24 range.
    • Keep DNS: if the hostname must work, don’t enable skip_name_resolve.
  2. Enable persistently in /etc/my.cnf.d/cpanel.cnf:
    [mysqld]
    skip_name_resolve = ON
    Restart MySQL.
  3. Verify the speedup: time mysql -h 127.0.0.1 -e "SELECT 1" before and after. New connections should be noticeably faster, especially if the host’s DNS resolver was slow.
  4. For caching DNS without disabling resolution, the alternative is to install a local resolver (unbound, dnsmasq) and point /etc/resolv.conf at 127.0.0.1. MySQL’s lookups then hit a local cache. Useful if you want to keep hostname grants but stop blocking on external DNS.
  5. Watch for Aborted_connects in the post-change period. If it climbs, an application that connected via hostname is failing — but the same connection over IP would also have failed because there’s no grant to match. Investigate that app’s connection config.
  6. For private-network database access where hosts are named via DNS, you can either keep hostname grants (and accept the DNS latency) or move to IPs (and accept that DHCP changes break grants). Most environments are happier with IPs and a documented mapping.
  7. The host_cache table (in performance_schema) shows MySQL’s cached DNS results. Even without skip_name_resolve, MySQL caches lookups — but the cache is small and entries expire. TRUNCATE TABLE performance_schema.host_cache flushes it.

For environments where MySQL connection latency matters and DNS infrastructure is shared with other systems, Stack Harbor’s environment management team audits the host-based grants, migrates them to IPs where safe, and enables skip_name_resolve as part of the connection-tuning baseline.