Local DNS: dnsmasq caching and intranet names
Local DNS caching plus names for intranet machines — dnsmasq does both in one package. But the measured path here is itself a minefield: systemd-resolved and SELinux both get in the way.
Install
Section titled “Install”sudo dnf install -y dnsmasqMeasured version 2.93.
Pitfall one: port 53 is taken
Section titled “Pitfall one: port 53 is taken”Fedora runs systemd-resolved by default, measured listening on:
127.0.0.53:53 127.0.0.54:53 # stub resolver192.168.122.1:53 # libvirt's own dnsmasqYour dnsmasq cannot bind 53 — including 127.0.0.1:53 (the stub covers the loopback semantics). This is design, not a bug: the desktop DNS chain is apps → 127.0.0.53 → upstream.
Pitfall two: SELinux blocks non-standard ports
Section titled “Pitfall two: SELinux blocks non-standard ports”Measured start with port=5353 failing outright:
dnsmasq: failed to create listening socket for port 5353: Permission deniedCheck the allowlist:
sudo semanage port -l | grep dns_port_tdns_port_t tcp 53, 853dns_port_t udp 53, 853Only 53 and 853. 5353 is not there (that is mDNS). Two routes:
# Route 1 (recommended): pick a port and label it permanentlysudo semanage port -a -t dns_port_t -p udp 5333sudo semanage port -a -t dns_port_t -p tcp 5333# Route 2: give up on the custom port, or move to 853 (DoT scenarios)Measured: with the labels added, port=5333 starts on the first try.
A working minimal config
Section titled “A working minimal config”/etc/dnsmasq.d/lab.conf:
listen-address=127.0.0.1port=5333server=223.5.5.5address=/mybox.test/192.168.2.247cache-size=1000Four lines, four jobs:
| Key | Purpose |
|---|---|
listen-address | loopback only — not a LAN DNS service |
server | forward misses upstream (Ali DNS here) |
address=/suffix/IP | resolve the whole intranet suffix to one IP |
cache-size | cache entry limit |
sudo systemctl enable --now dnsmasqVerify: intranet name and cache
Section titled “Verify: intranet name and cache”dig @127.0.0.1 -p 5333 mybox.test +short192.168.2.247Cache effect, two consecutive queries for the same name:
;; Query time: 67 msec ← first, upstream round trip;; Query time: 0 msec ← second, cache hit67ms→0ms is the entire value proposition; every resolver pointed at it benefits.
Making the system use it
Section titled “Making the system use it”A running service is not a working service. Point the system DNS at it:
# Desktop (NetworkManager-managed):sudo nmcli con mod "Wired connection 1" ipv4.ignore-auto-dns yes ipv4.dns "127.0.0.1"sudo nmcli con up "Wired connection 1"Note that with NetworkManager → resolved in the chain, resolved treats 127.0.0.1 as its upstream — resolved stays in front and dnsmasq becomes its caching backend. To put dnsmasq directly in front of applications you would disable the stub (DNSStubListener=no in /etc/systemd/resolved.conf, then restart) — on a desktop, think twice: it breaks NM’s DNS management.
Common traps
Section titled “Common traps”| Symptom | Cause |
|---|---|
failed to create listening socket ... Address already in use | resolved stub owns 53; use another port |
Permission denied on a custom port | SELinux dns_port_t allowlist; add via semanage |
| dnsmasq up but resolution unchanged | system DNS not pointed at it (check /etc/resolv.conf) |
| cache “not working” | the record’s TTL is 0 and should not be cached; read the TTL in the answer |
address= change has no effect | systemctl restart dnsmasq, or killall -HUP dnsmasq |
dig missing -p | non-standard ports require dig @127.0.0.1 -p port |
Related pages
Section titled “Related pages”- Networking and nmcli — pointing the system at it
- SELinux — the port labelling system
- journalctl —
journalctl -u dnsmasqdebugging - Upstream: dnsmasq manual