{"record":{"id":"8e7f7987210a1b6c","repo":"abiosoft/colima","slug":"failed-to-restart-dnsmasq-service-w","errorCode":null,"errorMessage":"failed to restart dnsmasq service: %w","messagePattern":"failed to restart dnsmasq service: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"environment/vm/lima/dns.go","lineNumber":102,"sourceCode":"\t// write config to dnsmasq directory\n\tif err := l.Write(\"/etc/dnsmasq.d/01-colima.conf\", buf.Bytes()); err != nil {\n\t\treturn fmt.Errorf(\"failed to write dnsmasq config: %w\", err)\n\t}\n\n\t// remove existing resolv.conf file\n\tif err := l.RunQuiet(\"sudo\", \"rm\", \"-f\", \"/etc/resolv.conf\"); err != nil {\n\t\treturn fmt.Errorf(\"failed to remove existing resolv.conf: %w\", err)\n\t}\n\n\t// replace resolv.conf with a custom one\n\tresolvConf := fmt.Sprintf(\"# Generated by Colima\\n\\nnameserver %s\\n\", internalIP)\n\tif err := l.Write(\"/etc/resolv.conf\", []byte(resolvConf)); err != nil {\n\t\treturn fmt.Errorf(\"failed to write resolv.conf: %w\", err)\n\t}\n\n\t// restart dnsmasq service to apply changes\n\tif err := l.RunQuiet(\"sudo\", \"systemctl\", \"restart\", \"dnsmasq\"); err != nil {\n\t\treturn fmt.Errorf(\"failed to restart dnsmasq service: %w\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":84,"sourceCodeEnd":107,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/environment/vm/lima/dns.go#L84-L107","documentation":"Final step of guest DNS setup: `sudo systemctl restart dnsmasq` inside the VM applies the new resolver configuration. Failure means systemd could not restart the service: dnsmasq not installed/enabled in the guest image, systemd not PID 1, unit masked, or the guest systemd still initializing. The error aborts the DNS setup chain (surfacing as 'error setting up DNS').","triggerScenarios":"Custom/forced disk images lacking the dnsmasq package; guest boot race where systemd units are not ready when the post-start action runs; SELinux/security policies blocking the restart; restarting while a previous dnsmasq instance holds port 53.","commonSituations":"Air-gapped users with --force-disk-image builds missing packages; slow machines where post-start runs before guest services settle; heavily locked-down corporate images.","solutions":["Retry the start; boot races with systemd usually clear on a second run.","If using a custom image, ensure dnsmasq is installed and not masked: `colima ssh -- systemctl status dnsmasq`.","Check `colima ssh -- sudo journalctl -u dnsmasq` for the unit-level failure and address it (port 53 conflicts, config syntax from earlier steps).","Fall back to DNS settings that bypass the in-guest resolver."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// verify guest dnsmasq before relying on in-guest DNS\n// colima ssh -- systemctl is-enabled dnsmasq && systemctl status dnsmasq","typeGuard":null,"tryCatchPattern":"Go: retry start once for systemd boot races; if the unit itself fails, inspect journalctl -u dnsmasq in the guest and switch DNS mode.","preventionTips":["Include dnsmasq in custom guest images","Don't mask dnsmasq unit","Give slow machines time between start and DNS-dependent operations"],"tags":["dns","dnsmasq","systemd","guest","colima"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}