Performance Tuning

Zero Latency DNS with Dnsmasq

Eliminate external DNS lookups for local domains on CentOS 7/8/9. Achieve 0ms internal resolution for PHP applications, WordPress, and API calls.

Read Time
5 minutes
Platform
CentOS 7/8/9
Performance Impact

See the latency reduction before and after implementing Dnsmasq:

100ms+
Before Dnsmasq
External DNS
0ms
After Dnsmasq
Local Cache
Performance Insight

DNS Resolution Flow
PHP Request
curl_get()
External DNS
20-100ms
Local Server
127.0.0.1

The Problem

By default, when your PHP scripts (like WordPress or Laravel) make requests to your own domain name, the server often leaves the local network to query public DNS servers. This adds 20ms–100ms of latencyFor every API call, cron job, or internal request. Multiplies quickly under load. per request.

Real Impact

On a 32GB high-performance VPS handling 1000 requests/second, this DNS overhead can consume significant CPU cycles and slow down your entire application stack.

Pro Tip

We use this setup to ensure internal CURL calls and cron jobs resolve instantly via the loopback interface (127.0.0.1), bypassing network stack overhead.

1. Install Dnsmasq

First, install the package via YUM:

Terminal
yum install dnsmasq -y
For CentOS 8 Stream or Rocky Linux, use dnf install dnsmasq -y

2. Configure Local Resolution

Edit the configuration file /etc/dnsmasq.conf. We want to force specific domains to point to the local server:

Configuration
# Listen only on localhost
listen-address=127.0.0.1
interface=lo
bind-interfaces

# Map your domains to the local IP
address=/cuddlr.net/127.0.0.1
address=/centos.support/127.0.0.1
address=/localhost/127.0.0.1

# Cache size for external queries
cache-size=1000
local-ttl=300

3. Update resolv.conf

Tell your OS to check the local Dnsmasq service before going to the internet. Edit /etc/resolv.conf:

Configuration
# Local Dnsmasq first
nameserver 127.0.0.1

# Fallback to Google DNS
nameserver 8.8.8.8
nameserver 8.8.4.4

# Prevent NetworkManager from overwriting
options timeout:1 attempts:1
Important Note

On CentOS 8+, you may need to disable NetworkManager's DNS management:

nmcli con mod "System eth0" ipv4.ignore-auto-dns yes

4. Verification

Restart the service and test the resolution time using dig:

Terminal
systemctl restart dnsmasq
systemctl enable dnsmasq
dig centos.support +stats
Expected Output
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: [timestamp]
;; MSG SIZE rcvd: 89
Test Your Setup
Query Time: 0 msec
Local Cache
Resolved via 127.0.0.1

Need Advanced DNS Architecture?

Our team specializes in complex multi-server DNS setups with failover and geographic routing.