fix(darwin): handle mDNSResponder on port 53 to avoid bind conflicts

When mDNSResponder is using port 53 on macOS, adjust listener config to
use 0.0.0.0:53, stop mDNSResponder before binding, and run cleanup on
install and uninstall so the DNS server can start reliably.
This commit is contained in:
Cuong Manh Le
2026-02-09 17:27:24 +07:00
committed by Cuong Manh Le
parent 40c68a13a1
commit a4f0418811
5 changed files with 224 additions and 0 deletions
+16
View File
@@ -359,6 +359,10 @@ NOTE: running "ctrld start" without any arguments will start already installed c
initInteractiveLogging()
tasks := []task{
{func() error {
doMdnsResponderCleanup()
return nil
}, false, "Cleanup service before installation"},
{func() error {
// Save current DNS so we can restore later.
withEachPhysicalInterfaces("", "saveCurrentStaticDNS", func(i *net.Interface) error {
@@ -374,6 +378,10 @@ NOTE: running "ctrld start" without any arguments will start already installed c
}, false, "Configure service failure actions"},
{s.Start, true, "Start"},
{noticeWritingControlDConfig, false, "Notice writing ControlD config"},
{func() error {
doMdnsResponderHackPostInstall()
return nil
}, false, "Configure service post installation"},
}
mainLog.Load().Notice().Msg("Starting existing ctrld service")
if doTasks(tasks) {
@@ -437,6 +445,10 @@ NOTE: running "ctrld start" without any arguments will start already installed c
}
tasks := []task{
{func() error {
doMdnsResponderCleanup()
return nil
}, false, "Cleanup service before installation"},
{s.Stop, false, "Stop"},
{func() error { return doGenerateNextDNSConfig(nextdns) }, true, "Checking config"},
{func() error { return ensureUninstall(s) }, false, "Ensure uninstall"},
@@ -459,6 +471,10 @@ NOTE: running "ctrld start" without any arguments will start already installed c
// Note that startCmd do not actually write ControlD config, but the config file was
// generated after s.Start, so we notice users here for consistent with nextdns mode.
{noticeWritingControlDConfig, false, "Notice writing ControlD config"},
{func() error {
doMdnsResponderHackPostInstall()
return nil
}, false, "Configure service post installation"},
}
mainLog.Load().Notice().Msg("Starting service")
if doTasks(tasks) {