MySQL DNS Resolution Warning: Fixing “IP address could not be resolved” Error in Virtualized Environments


1 views

When working with MySQL in virtualized environments (particularly MySQL 5.6.3 on CentOS 6.1 hosted in VirtualBox), you might encounter persistent warnings in your logs:

[Warning] IP address '192.168.1.201' could not be resolved: Temporary failure in name resolution

This occurs despite having proper forward DNS resolution working for general internet access. The issue stems from MySQL's default behavior of performing reverse DNS lookups for client connections.

MySQL performs hostname resolution for:

  • Security checks (hostname verification in grants)
  • Performance monitoring (hostname display in processlist)
  • Logging purposes

In virtualized bridge networks, reverse DNS often fails because:

1. Home routers typically don't maintain PTR records
2. Virtual machines may have incomplete DNS configurations
3. The resolution timeout causes connection delays

Option 1: Disable reverse DNS lookups (Recommended for development environments)

# Add to your my.cnf under [mysqld]
skip-name-resolve

This tells MySQL to work exclusively with IP addresses. After making this change:

sudo service mysql restart

Option 2: Proper DNS Configuration (For production environments)

Ensure your /etc/hosts contains entries for all connecting hosts:

192.168.1.201  dev-workstation
192.168.1.200  mysql-vm

Then configure MySQL to use hosts file:

# In my.cnf
[mysqld]
hosts-file=/etc/hosts

Check if resolution is working with:

mysqladmin -uroot -p ping
nslookup 192.168.1.201
dig -x 192.168.1.201

For persistent issues, consider network-level solutions:

# Adjust DNS timeouts in /etc/nsswitch.conf
hosts:      files dns [timeout=1]

Each failed DNS lookup can add 500ms-5s delay per connection. In high-traffic scenarios, this creates:

  • Connection pooling challenges
  • Application timeouts
  • Resource exhaustion

Benchmark before/after changes with:

mysqlslap --concurrency=100 --iterations=10 --query="SELECT 1"

When running MySQL 5.6.3 on a CentOS 6.1 VM through VirtualBox with bridged networking, you might encounter persistent warnings like:

[Warning] IP address '192.168.1.201' could not be resolved: Temporary failure in name resolution

This occurs despite normal DNS functionality for forward lookups. The system struggles specifically with reverse DNS resolution for client connections.

The current VM network setup shows:

# Current ifcfg-eth0 configuration
DEVICE="eth0"
HWADDR="08:00:27:4B:3D:7C"
NM_CONTROLLED="yes"
ONBOOT="yes"
NETMASK=255.255.255.0
IPADDR=192.168.1.200
GATEWAY=192.168.1.1
PEERDNS=yes

# DNS configuration
nameserver 192.168.1.1

MySQL performs reverse DNS lookups by default for:

  • Hostname verification in grant tables
  • Security checks
  • Connection logging

In bridged mode, while forward DNS works, reverse lookups may fail because:

  1. Your local router (192.168.1.1) might not properly handle PTR records
  2. The client IP (192.168.1.201) might not have a corresponding PTR record
  3. VirtualBox's bridged networking might introduce slight delays that trigger timeouts

Option 1: Skip Name Resolution in MySQL

Add to your my.cnf (most efficient solution):

[mysqld]
skip-name-resolve

This tells MySQL to work only with IP addresses, bypassing DNS entirely. After changing, restart MySQL:

service mysqld restart

Option 2: Configure Local Hosts File

Add entries to /etc/hosts on both machines:

# On the VM (192.168.1.200)
192.168.1.201 host-machine

# On the host (192.168.1.201)
192.168.1.200 mysql-vm

Option 3: Verify DNS Forward/Reverse Consistency

Test your DNS setup with:

# Forward lookup
nslookup host-machine 192.168.1.1

# Reverse lookup
nslookup 192.168.1.201 192.168.1.1
Solution DNS Queries Security Impact Implementation Effort
skip-name-resolve None Slight reduction (no hostname verification) Low (config change only)
/etc/hosts entries None None Medium (multi-machine changes)
Fix DNS server Full functionality None High (admin privileges needed)

If problems persist, check:

# Verify network connectivity
ping 192.168.1.201

# Test DNS resolution time
time host 192.168.1.201

# Check MySQL connection timing
mysqladmin -h 192.168.1.200 -u root -p processlist