Setup DNSMasq for DNS local caching

RoomIT
Feb 7, 2023

--

Setup DNSMasq for DNS local caching

Install DNSMASQ

yum install dnsmasq -y 

Or

apt install dnsmasq -y    

Configuration DNSMASQ

After that add this configuration at the end of file /etc/dnsmasq.conf.

port=53
domain-needed
interface=lo
listen-address=127.0.0.1
bind-interfaces
resolv-file=/etc/resolv-dnsmasq.conf
strict-order
no-hosts #or expand-hosts (no-host | Disable read /etc/hosts)
domain=roomit.xyz
cache-size=1000
local-ttl=14400
min-cache-ttl=3600
log-queries
log-facility=/var/log/dnsmasq.log

Add DNS Resolver in File /etc/resolv-dnsmasq.conf

nameserver 8.8.8.8
nameserver 1.1.1.1

Restart Service

systemctl restart dnsmasq
systemctl enable dnsmasq

Clear DNS Cache

systemctl restart dnsmasq
or
pkill -HUP dnsmasq

To check the content of the cache we can use the command below and the result we can see on the log file.

pkill -USR1 dnsmasq

--

--

RoomIT
RoomIT

Written by RoomIT

Our Notes For Blockchain | DevOps | Security | Sysadmin

No responses yet