Eliminate external DNS lookups for local domains on CentOS 7/8/9. Achieve 0ms internal resolution for PHP applications, WordPress, and API calls.
See the latency reduction before and after implementing Dnsmasq:
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.
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.
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.
First, install the package via YUM:
yum install dnsmasq -y
dnf install dnsmasq -y
Edit the configuration file /etc/dnsmasq.conf. We want to force specific domains to point to the local server:
# 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
Tell your OS to check the local Dnsmasq service before going to the internet. Edit /etc/resolv.conf:
# 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
On CentOS 8+, you may need to disable NetworkManager's DNS management:
nmcli con mod "System eth0" ipv4.ignore-auto-dns yes
Restart the service and test the resolution time using dig:
systemctl restart dnsmasq
systemctl enable dnsmasq
dig centos.support +stats
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: [timestamp]
;; MSG SIZE rcvd: 89
Our team specializes in complex multi-server DNS setups with failover and geographic routing.