Skip to content
Search Fedora

    Browse this documentation

    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.

    Terminal window
    sudo dnf install -y dnsmasq

    Measured version 2.93.

    Fedora runs systemd-resolved by default, measured listening on:

    127.0.0.53:53 127.0.0.54:53 # stub resolver
    192.168.122.1:53 # libvirt's own dnsmasq

    Your 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 denied

    Check the allowlist:

    Terminal window
    sudo semanage port -l | grep dns_port_t
    dns_port_t tcp 53, 853
    dns_port_t udp 53, 853

    Only 53 and 853. 5353 is not there (that is mDNS). Two routes:

    Terminal window
    # Route 1 (recommended): pick a port and label it permanently
    sudo semanage port -a -t dns_port_t -p udp 5333
    sudo 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.

    /etc/dnsmasq.d/lab.conf:

    listen-address=127.0.0.1
    port=5333
    server=223.5.5.5
    address=/mybox.test/192.168.2.247
    cache-size=1000

    Four lines, four jobs:

    KeyPurpose
    listen-addressloopback only — not a LAN DNS service
    serverforward misses upstream (Ali DNS here)
    address=/suffix/IPresolve the whole intranet suffix to one IP
    cache-sizecache entry limit
    Terminal window
    sudo systemctl enable --now dnsmasq
    Terminal window
    dig @127.0.0.1 -p 5333 mybox.test +short
    192.168.2.247

    Cache effect, two consecutive queries for the same name:

    ;; Query time: 67 msec ← first, upstream round trip
    ;; Query time: 0 msec ← second, cache hit

    67ms→0ms is the entire value proposition; every resolver pointed at it benefits.

    A running service is not a working service. Point the system DNS at it:

    Terminal window
    # 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.

    SymptomCause
    failed to create listening socket ... Address already in useresolved stub owns 53; use another port
    Permission denied on a custom portSELinux dns_port_t allowlist; add via semanage
    dnsmasq up but resolution unchangedsystem 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 effectsystemctl restart dnsmasq, or killall -HUP dnsmasq
    dig missing -pnon-standard ports require dig @127.0.0.1 -p port