Upgrading to macOS Sequoia broke mDNS for me.
My M2 MacBook stopped responding when pinging its host name lithium.local
.
The Anki sync server
running on it became unreachable. It did not matter whether I attempted to
resolve lithium.local
from another machine or on that machine itself.
Searching the system log for clues, or changing mDNS related configurations did not help. Turning it off and on again did not either.
Searching system logs for hints turned out to be a rabbit hole. On Debian or
NixOS, I can always just search the logs in /var/log
or journalctl
for
hints. Recent macOS versions are really good at
masking useful debug information
in logs. Various guides,
like here,
advise you to add a configuration profile to unmask log information: 5 minutes
later and you are in a Apple Configurator rabbit hole.
All I need is to map a host name to an IP address, without relying on a central
DNS server. Before giving in and just adding the affected machine’s IP address
to every single /etc/hosts
file on all my computers, I wanted to find a
dumb-but-it-works quick-fix.
I want to show you a workaround for getting your macOS to respond to mDNS queries again without having to reinstall macOS:
If you ever encounter your macOS machine not responding to mDNS queries because
mDNSResponder
gave up working, you can use dns-sd -R
. Just run the
following command:
# Assuming that $(hostname) is your machine's host name
dns-sd -R $(hostname).local _device-info._tcp local 0
Verify that it works by querying your machine’s host name using dns-sd -q
:
dns-sd -q $(hostname).local
DATE: ---Sat 21 Dec 2024---
22:31:11.112 ...STARTING...
Timestamp A/R Flags IF Name Type Class Rdata
22:31:11.113 Add 40000003 1 $HOST.local. Addr IN 127.0.0.1
22:31:11.113 Add 40000002 11 $HOST.local. Addr IN 192.x1.y2.z3
mDNS and DNS are similar to a large degree. In the transport layer, mDNS is DNS. In the network layer, mDNS sends packets out as multicast instead. Seriously, it’s mind-blowing
Theoretically, you should be able to run the following dig
invocation and get
the same result as the above dns-sd -q
.
dig +short @224.0.0.251 -p 5353 $(hostname).local
You can intercept mDNS query using the following tcpdump
invocation:
sudo tcpdump -i lo0 -n 'port 5353'
When tcpdump
then intercepts the query with dig
, you will see something
similar to the following:
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on lo0, link-type NULL (BSD loopback), snapshot length 262144 bytes
22:37:12.525546 IP 127.0.0.1.52740 > 224.0.0.251.5353: 19746+ [1au] A (QM)? $HOST.local. (54)
22:37:12.528499 IP 127.0.0.1.5353 > 127.0.0.1.52740: 19746*- 1/0/1 A 192.x1.y2.z3 (75)
Unfortunately, running dig
like above doesn’t show me the query results in
there, but please write me if it works on your machine.