abiosoft/colima · error

error adding route for %s via %s: %w

Error message

error adding route for %s via %s: %w

What it means

On macOS, colima runs 'sudo /sbin/route add -net <BridgeSubnet> <vmIP>' to make the incus bridge reachable from the host, and route returned non-zero. Despite the stale-route removal just before, the common cause is the route already existing (removal silently failed) or the VM IP being stale/invalid at that moment.

Source

Thrown at environment/container/incus/route.go:41

	vmIP := limautil.IPAddress(config.CurrentProfile().ID)
	if vmIP == "127.0.0.1" || vmIP == "" {
		return nil
	}

	if !util.SubnetAvailable(BridgeSubnet) {
		log.Warnf("subnet %s conflicts with host network, skipping route setup", BridgeSubnet)
		return nil
	}

	if err := embedded.InstallSudoers(c.host); err != nil {
		return fmt.Errorf("error setting up sudoers for route: %w", err)
	}

	// delete any stale route first (ignore errors)
	_ = c.removeContainerRoute()

	if err := c.host.RunQuiet("sudo", "/sbin/route", "add", "-net", BridgeSubnet, vmIP); err != nil {
		return fmt.Errorf("error adding route for %s via %s: %w", BridgeSubnet, vmIP, err)
	}

	return nil
}

// removeContainerRoute removes the macOS route for the Incus container subnet.
func (c *incusRuntime) removeContainerRoute() error {
	if !util.MacOS() {
		return nil
	}

	if !util.RouteExists(BridgeSubnet) {
		return nil
	}

	return c.host.RunQuiet("sudo", "/sbin/route", "delete", "-net", BridgeSubnet)
}

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Remove the stale route manually: 'sudo route -n delete <BridgeSubnet>' then retry start
  2. Check existing routes: 'netstat -rn | grep <BridgeSubnet>'
  3. Verify the VM IP is current: 'colima list' / limactl output vs 'route get' results
  4. Temporarily disconnect VPN if it fights colima's route management

Example fix

# before (stale route blocks add)
route add fails: 'File exists'
# after
sudo route -n delete 2001:db8:abcd::/64 2>/dev/null; colima restart
Defensive patterns

Strategy: fallback

Validate before calling

// make route add idempotent: check existence first
if util.RouteExists(BridgeSubnet) {
    _ = c.removeContainerRoute()
}

Try / catch

if err := c.host.RunQuiet("sudo", "/sbin/route", "add", "-net", BridgeSubnet, vmIP); err != nil {
    if strings.Contains(err.Error(), "File exists") {
        _ = c.removeContainerRoute()
        return c.host.RunQuiet("sudo", "/sbin/route", "add", "-net", BridgeSubnet, vmIP)
    }
    return fmt.Errorf("error adding route for %s via %s: %w", BridgeSubnet, vmIP, err)
}

Prevention

When it happens

Trigger: host.RunQuiet('sudo','/sbin/route','add','-net',subnet,vmIP) fails: route already present (add is not idempotent), vmIP no longer assigned to the VM, sudo denied, or the subnet string is rejected.

Common situations: Repeated colima start/stop cycles leaving a stale route, VM IP changed after host network change (Wi-Fi to VPN), VPN clients manipulating the routing table concurrently.

Related errors


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