abiosoft/colima · error

failed to restart dnsmasq service: %w

Error message

failed to restart dnsmasq service: %w

What it means

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').

Source

Thrown at environment/vm/lima/dns.go:102

	// write config to dnsmasq directory
	if err := l.Write("/etc/dnsmasq.d/01-colima.conf", buf.Bytes()); err != nil {
		return fmt.Errorf("failed to write dnsmasq config: %w", err)
	}

	// remove existing resolv.conf file
	if err := l.RunQuiet("sudo", "rm", "-f", "/etc/resolv.conf"); err != nil {
		return fmt.Errorf("failed to remove existing resolv.conf: %w", err)
	}

	// replace resolv.conf with a custom one
	resolvConf := fmt.Sprintf("# Generated by Colima\n\nnameserver %s\n", internalIP)
	if err := l.Write("/etc/resolv.conf", []byte(resolvConf)); err != nil {
		return fmt.Errorf("failed to write resolv.conf: %w", err)
	}

	// restart dnsmasq service to apply changes
	if err := l.RunQuiet("sudo", "systemctl", "restart", "dnsmasq"); err != nil {
		return fmt.Errorf("failed to restart dnsmasq service: %w", err)
	}

	return nil
}

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Retry the start; boot races with systemd usually clear on a second run.
  2. If using a custom image, ensure dnsmasq is installed and not masked: `colima ssh -- systemctl status dnsmasq`.
  3. Check `colima ssh -- sudo journalctl -u dnsmasq` for the unit-level failure and address it (port 53 conflicts, config syntax from earlier steps).
  4. Fall back to DNS settings that bypass the in-guest resolver.
Defensive patterns

Strategy: retry

Validate before calling

// verify guest dnsmasq before relying on in-guest DNS
// colima ssh -- systemctl is-enabled dnsmasq && systemctl status dnsmasq

Try / catch

Go: retry start once for systemd boot races; if the unit itself fails, inspect journalctl -u dnsmasq in the guest and switch DNS mode.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/8e7f7987210a1b6c. Report an issue: GitHub.